关于满二叉树:
- 如果一颗树深度为d,最大层数为k;
- 它的叶子数是: 2^(d-1);
- 第k层的节点数是: 2^(k-1);
- 总节点数是: 2^k-1 (2的k次方减一)
- 总节点数一定是奇数。
关于二叉树的遍历:
- 先序遍历:根节点——左子树——右子树
- 中序遍历:左子树——根节点——右子树
- 后序遍历:左子树——右子树——根节点
- 已知先序或后序,又知中序,则可以确定唯一的二叉树
- 因为先序和后序只反映了节点间的父子关系,没有反映出左右关系。
持续更新...
------------------------------------N久之后再战的分割线--------------------------------------------
一生之敌二叉树。。。我来更新了。。。
满二叉树一定是完全二叉树,完全二叉树不一定是满二叉树。
树的度的意思是是树中结点最大的度。
各度的结点数量之和=各度*各度的结点数+1(左边是结点总数,右边边数+1也是结点总数)。用这个可以解决计算结点的问题。
物理结构为数组,逻辑结构为树。
----------------------------------------3个小时后的更新---------------------------------------------
二叉树的JAVA代码实现,先序遍历中序遍历和后序遍历。
/** * Created by Administrator on 2017/8/28. */ public class BinaryTree { private Node root; public Node getRoot() { return root; } public void createMyTree() { root = new Node(1); Node nodeB = new Node(2); Node nodeC = new Node(3); Node nodeD = new Node(4); Node nodeE = new Node(5); Node nodeF = new Node(6); Node nodeG = new Node(7); root.left = nodeB; root.right = nodeC; nodeB.left = nodeD; nodeB.right = nodeE; nodeC.left = nodeF; nodeC.right = nodeG; } public static void preOrderRecur(Node head) { if (head == null) { return; } System.out.print(head.value + " "); preOrderRecur(head.left); preOrderRecur(head.right); } public static void inOrderRecur(Node head) { if (head == null) { return; } inOrderRecur(head.left); System.out.print(head.value + " "); inOrderRecur(head.right); } public static void posOrderRecur(Node head) { if (head == null) { return; } posOrderRecur(head.left); posOrderRecur(head.right); System.out.print(head.value + " "); } public static void main(String[] args) { BinaryTree tree = new BinaryTree(); tree.createMyTree(); System.out.print("先序遍历:"); preOrderRecur(tree.getRoot()); System.out.println(); System.out.print("中序遍历:"); inOrderRecur(tree.getRoot()); System.out.println(); System.out.print("后序遍历:"); posOrderRecur(tree.getRoot()); } } class Node { public int value; public Node left; public Node right; public Node() { } public Node(int value) { this.value = value; } }
控制台打印:
先序遍历:1 2 4 5 3 6 7 中序遍历:4 2 5 1 6 3 7
后序遍历:4 5 2 6 7 3 1
1494

被折叠的 条评论
为什么被折叠?



