"Data Structures and Algorithms": Tree and two fork tree definitions, basic terms and properties

Source: Internet
Author: User

Definition and basic terminology of trees

? Tree: is a kind of important nonlinear data structure, which is a hierarchical structure defined by branching relationship.? Root: A tree is a finite set t of N (n>=0) nodes, for a non-empty tree, where there is only one specific node, called the treeroot (rooted)。? sub-tree: When n>1, the remaining nodes can be divided into m (m>0) non-intersecting finite set t1,t2,...... Tm, where each set itself is a tree, called the root of theSub-tree (subtree)。 The root node of each subtrees tree has and has only one direct precursor, but can have 0 or more direct successors.
node:Contains a data element and several branches that point to the subtree.the degree of the nodal point:The number of tree nodes.
the degree of the tree:The largest node degree in the tree.
leaf knot:Also called terminal node, which is a node with a degree of 0.
Branching nodes:The node with a degree of not 0.
path from ROOT to node:is composed of branches and nodes from the root to the node.
your child's knot point:The root of the node's subtree is called the child of the node.
parent Knot points:b nodes are children of a node, and the A node is the parent of the B node.
Brother Knot:Children of the same parents.
Cousin's knot point:Nodes on the same layer.
ancestor nodes.:All nodes on the branch from the root to the nodedescendants ' Knot point:Any node in a subtree that is rooted in a node is called a descendant of that node.
the level of the node:The layer of the root node is defined as 1, the child of the root is the second node, and so on.
depth of tree:The largest node layer in the tree.
ordered Tree:Tree ordered by the subtree.
unordered Tree:The order of the subtree is not considered.
Forest:M (m>=0) a collection of disjoint trees.

Linear structure: First Data element (no precursor), last data Element (no successor), other data element (one precursor, one successor)
Tree: Root node (no precursor), multiple leaf nodes (no successor), other nodes in the tree (one precursor, multiple successors)

Two fork Tree

definition: The two fork tree is a finite set of n (n30) nodes, which is either an empty tree (n=0), or a root node and two disjoint two fork trees, respectively called the Saozi right subtree.


1. There are at most two subtrees trees per node (i.e. nodes with no more than 2);

2. The sub-tree of the two fork tree has left and right points, and its order cannot be arbitrarily reversed.

Five basic forms of two-fork tree

( 1 ) Full two fork tree

A two-prong tree with a depth of K and a knot is called a full two-tree .

Features: The number of nodes on each layer is the maximum number of nodes.

( 2 ) Complete binary tree

A depth of K, a two-fork tree with n nodes, is called a complete binary tree when and only if each of its nodes corresponds to a node one by one in a full two-tree with a depth of k, numbered from 1 to N.

Features: Leaf nodes may only appear on the two most layered layers. For any node, if the maximum level of the descendants of the right branch is L, then the maximum level of the descendants of the left branch must be L or l+1.

The two fork tree has the following important properties:
Property 1The number of nodes on the first layer of the binary tree is 2i-1 (i≥1).
Proof: To prove by mathematical induction:
Inductive basis: When I=1, there is 2i-1=20=1. Because there is only one root node on the 1th floor, the proposition is set up.
Inductive hypothesis: Assuming that all J (1≤j<i) propositions are established, that is, there are at most 2j-1 nodes on level J, proving that the proposition of J=i is also established.
Inductive steps: According to the inductive hypothesis, there are at most 2i-2 nodes on the i-1 layer. Since there are at most two children per node of a binary tree, the number of nodes on layer I is at most twice times the maximum number of nodes on the i-1 layer. That is, when j=i, there are at most 2x2i-2=2i-1 nodes on this layer, so the proposition is established.
Property 2A two-fork tree with a depth of K has at most 2k-1 nodes (k≥1).
Proof: In a two-fork tree with the same depth, the number of nodes in the tree is the highest only if each layer contains the largest node count. Therefore, the number of nodes with a two-fork tree with a depth of K is up to: 1.
So the proposition is correct.
Property 3In any-tree binary tree, if the number of terminal nodes is N0, the degree of 2 node is N2, then no=n2+1.
Proof: Because all nodes in the binary tree are not more than 2 degrees, the total number of nodes (recorded as n) should be equal to the sum of 0 degree nodes, 1 degree nodes (recorded as N1) and 2 degree nodes:
N=NO+N1+N2 (Formula 1)
On the other hand, 1-degree nodes have a child, 2-degree nodes have two children, so the total number of child nodes in the binary tree is:
Only the root node in the tree is not a child of any node, so the total number of nodes in the binary tree can be expressed as:
N=n1+2n2+1 (Formula 2)
obtained by the Formula 1 and the 2:

"Data Structures and Algorithms": Tree and two fork tree definitions, basic terms and properties

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.