Teaching Objective: to master the basic concepts and terms of tree and binary tree, the nature of binary tree
Teaching emphases: the definition of two fork tree and the nature of binary tree
Teaching Difficulty: The nature of two fork tree
Teaching Content:
The definition of a tree:
A tree is a finite set of n (n>=0) nodes. In any of a non-empty tree:
(1) Having and having only one specific node called the root;
(2) When n>1, the remaining nodes can be divided into m (m>0) disjoint finite set t1,t2,... Tm, where each collection itself is a tree, and is called the root subtree.
Second, the basic concept of the tree:
The node of a tree contains a data element and several branches that point to its subtree.
The number of subtrees owned by a node is called the degree of the node.
A node with a degree of 0 is called a leaf or terminal node.
A node with a degree of not 0 is called a non terminal node or branch node.
The degree of a tree is the maximum of the degrees of each node in the tree.
The root of the subtree of the node is called the child of the node, and correspondingly, the node is called the child's parents.
The children of the same parents are called brothers.
The ancestor of the node is all nodes from the root to the branch of the node.
Any node in a subtree rooted in a node is called the descendant of the node.
The level of the node is defined from the root, the root is the first layer, and the child of the root is the second layer. Their parents are cousins to each other at the same level of nodes. The maximum level of nodes in a tree is called the depth, or height, of the tree.
If each subtree of a node in a tree is ordered from left to right, the tree is called a sequential tree, otherwise called a unordered tree.
A forest is a collection of m>=0 trees of M (s).
Definition of three or two fork tree
The binary tree is another kind of tree structure, it is characterized by at most only two Shang tree (that is, the node in the binary tree does not exist more than 2), and the subtree of the binary tree has the left and right points, its order can not be arbitrarily reversed.
A two-fork tree with a depth of K and 2 (k)-1 nodes is called a full two-forked tree, as shown in figure (a), numbered per node by icon, if there is a depth of k, there are n nodes of the two-tree, when and only if each of its nodes with a depth of K two-tree number from 1 to n node one by one corresponding, called the complete binary tree.
The binary tree is defined as follows:
ADT binarytree{
A data Object D:D is a collection of data elements with the same attributes.
Data relation R:
Basic Operations P:
Initbitree (&t);
Destroybitree (&t);
Createbitree (&t,definition);
Clearbitree (&t);
Bitreeempty (T);
Bitreedepth (T);
Root (T);
Value (t,e);
Assign (T,&e,value);
Parent (t,e);
Leftchild (t,e);
Rightchild (t,e);
Leftsibling (t,e);
Rightsibling (t,e);
Insertchild (T,P,LR,C);
Deletechild (T,P,LR);
Preordertraverse (T,visit ());
Inordertraverse (T,visit ());
Postordertraverse (T,visit ());
Levelordertraverse (T,visit ());
}adt BinaryTree
The properties of the three or two-forked tree
| Nature 1: |
There are at most 2 i-1 nodes (I>=1) on the first layer of the binary tree. |
|
| Nature 2: |
A two-forked tree with a depth of K has a maximum of 2 K-points minus 1 nodes (k>=1). |
|
| Nature 3: |
For any binary tree T, if its terminal node number is N0, the number of degrees 2 is N2, then n0=n2+1. |
|
| Nature 4: |
The depth of the complete binary tree with n nodes is |log2n|+1 |
|
| Nature 5: |
If the node of a complete binary tree with n nodes is numbered by sequence, then to any node I (1=<i=<n) there are:
(1) If i=1, then the node i is the root of the two-fork tree, no parents; if i>1, then the parent parent (i) is the node I/2
(2) If 2i>n, then node I without left child (node I for leaf node); otherwise, the left child lchild (i) is the node 2i.
(3) If 2i+1>n, then the node I have no right child; otherwise the right child rchild (i) is the node 2i+1 |
|