Binary Tree
1 property:
1.1、在二叉树的第i层上至多有2^(i-1)个结点。
1.2、深度为k的二叉树至多有2^k - 1 个结点。
1.3、对任何一颗二叉树T,如果其终端结点数为n0,度为2的结点数为n2,则n0 = n2+1。
inference :
n = n0 + n1 + n2
n = B + 1;
B = n1 + 2*n2;
n = n1 + 2*n2 +1;
0 = n2 - n0+1;
so : n0 = n2 +1;
1.4、具有n个结点的完全二叉树的深度为log2^n(下取整) + 1。
1.5、如果对一棵有n个结点的完全二叉树(其深度为log2^n(下取整) + 1)的结点按层序编号(从第1层到第log2^n(下取整) + 1层,每层从左到右),则对任一结点 i(1<=i<=n),有
(1)如果i=1,则结点i是二叉树的根,无双亲;如果i>1 , 则其双亲PARENT(i)是结点i/2下取整。
(2)如果2i>n ,则结点i无左孩子,否则其左孩子是结点2i。
(3)如果2i+1>n,则结点i无右孩子,否则其右孩子是结点2i+1。
2 storage structure of binary tree
2.1、Sequential storage structure
2.2、Linked storage structure
typedef struct BiTNode
{
TElemType data;
struct BiTNode *lchild,*rchild;
}
-----------------------basic operation ------------------------
(1)Status CreateBiTree(BiTree &T)
//按先序次序输入二叉树中结点的值,空格字符表示空树,构造二叉链表表示的二叉树T。
(2)Status PreOrderTraverse(BiTree T,Status(*Visit)(TElemType e));
//先序遍历二叉树
1: 递归方式
2:非递归方式
(3)Status InOrderTraverse(BiTree T,Status(*Visit)(TElemType e));
//中序遍历二叉树
1: 递归方式
2:非递归方式
(4)Status PostOrderTraverse(BiTree T,Status(*Visit)(TElemType e));
1: 递归方式
2: 非递归方式
方法一:
方法二:
(5)Status LevelOrderTraverse(BiTree T,Status(*Visit)(TElemType e));
队列法:
双栈法:
3Threaded binary tree
3.1二叉树的中序线索化
3.2二叉树的中序线索遍历