Introduction to six tree data structure

Related Terms tree

Node: A data element and a plurality of other nodes of the branch point of the composition

Degree: the degree of node: the sub-tree node (i.e., branches of the tree)

        Maximum node degree of the book: of Trees

Leaf (terminal node): the node is equal to zero

Non-terminal node: node is not zero degree

Children (child node): a root node of words called the child node

Parent (parent): a node is called the parent of all the sub-root node

Ancestors: ancestor node refers to all nodes on the path of this root node path

Sons: all nodes on a branch of a node to a leaf node is called the node's descendants

Brothers: call each other brothers of the same parents of children between

Node Hierarchy: counting from the root, root for the first layer, which second layer on the child ...., L layer are any child nodes on layer L + 1.

Cousins: its parent node in the same layer

The maximum level tree nodes: the depth of the tree

Ordered tree: the sub-tree if the tree each node is left to right order, not interchangeable, called ordered tree

Unordered tree: if the subtree tree node is no order, can be interchanged, the tree becomes disordered

Forest: Yes M> = 0 set tree

 

 

Binary Tree

Definition:
binary tree is a finite set of n nodes of the (n> = 0), which is empty, or (n = 0),
or consists of a root and two disjoint left subtree and right subtree composition, and
left subtree and right subtrees are also binary
characteristics:
① binary tree may be empty, called an empty binary tree ;
② each node at most only have two children;
③ subtree the left and right of the points and the order can not be reversed .

 

 Binary tree node subtree subtree to distinguish between left and right sub-tree, even if only a sub-tree also
want to distinguish that it is the left sub-tree, or right subtree. This is the binary tree of
the main differences. The map shows the binary tree five basic form , FIG. (C), and (d) are not
the same two binary.

 

 Binary tree properties:

1, in the binary tree I (i> = 1) layer has many 2 I-1 nodes

2, a depth of k (k> = 1) of the binary tree has at most 2k-1 nodes

3, any of a binary tree, if it is the terminal number of nodes n0, n2 bits of the number of nodes is 2, then n0 = n2 + 1

 

Full Binary - depth of k (k> = 1) and there are 2 K binary tree nodes -1

A full binary tree nodes in sequence number: a top-down starts from the first node layer, numbered consecutively from left to right

 

 

Complete binary tree: Depth binary bits of K, K-1 is a full layer nodes (2k-2), K is a left node continuous layer (i.e., node numbers are continuous)

Full binary tree complete binary tree is a special case

4. The depth of a complete binary tree with n nodes is [log2n] +1 

5.  Full node binary tree has n number of nodes in layers
( from layer 1 to [log 2 n] + 1'd layers, each left to right ),
the node I of any one of (1 ≦ i ≦), are:
(1) if i = 1 , then node i no parent, is the root of the binary tree ;
if i> 1 , the i parent parent (a) is a node i / 2 ;
(2) if 2 * i≤n , then its left child is node i * 2 ,
otherwise, i no left child node and a leaf node;
(3) if 2 * i + 1 ≤ N , then its right child is node i + 1 * 2 ,
otherwise, no right child node i

 

 Sequential storage binary tree structure

It is a set of contiguous memory locations storing binary data elements. Thus, must all nodes of a binary tree arrangement to become a proper sequence, to node in this sequence is the mutual positions reflect the logical relationship between the junction points, number of methods available.

 

二叉树的顺序存储结构——即对二叉树按完全二叉树进行编号,然后用一维数组存储,其中编号为i的结点存储在数组中下标为i的分量中。

——该方法称为“以编号为地址” 策略

 

 

 

 

二叉树的链式存储结构  

 二叉链表示法 :左边指针是左孩子 ,右边指针是右孩子

 

 

 

1 二叉链表类型定义
2 typedef struct btnode {
3 DataType data;
4 struct btnode *lchild,*rchild;
5 }*BinTree;;

 

 在含n个结点的二叉链表中有2n个指针域,其中n-1个用来指向结点的左右孩子,其余n+1个空链域

 

Guess you like

Origin www.cnblogs.com/X404/p/12097225.html