Two-fork Tree

Source: Internet
Author: User

A Two-ary tree is a finite set of n (n>=0) nodes, either an empty set (a null binary tree) or a Saozi right subtree separated by a root node and two disjoint, respectively called the root node . Two-fork tree.  

two characteristics of the fork tree Each node has a maximum of two subtrees trees, so there are no nodes in the binary tree that are more than 2. (Note: Not all need two subtrees trees, but can be up to two trees, no subtree or a subtrees tree is also possible.) )

Saozi the right subtree is ordered, and the order cannot be reversed.

Even if a node in the tree has only one subtrees tree, it is Zuozi or right subtree, and below is a completely different two-fork tree:

Five basic forms of the two-fork tree : empty Two-fork tree There's only one root node.

Root Knot dot only left dial hand Tree

The root node is only the right sub-tree.

The root node has both Zuozi and right sub-trees.  

full two fork tree in a binary tree , if all branch nodes have Saozi right subtree, and all the leaves are on the same layer, such a two-fork tree is called a full two-fork tree.  

The features of the two-fork tree are:

A. leaves can only be present on the next level.

B. the degree of non-leaf junction must be 2.

c. In the same depth of the two-fork tree, the number of nodes full of two trees must be the most, while the leaves are the most.

Complete binary Tree

for a two-prong tree with n nodes numbered in the sequence, if the node numbered I (1<=i<=n) is exactly the same as the node in the full two-fork tree with the same depth, the binary tree is called a complete binary tree.  

The features of the complete binary tree are:

leaf nodes can only appear in the bottom two floors . .

The lowest-level leaves must be concentrated in the left-hand continuous position.

The second-to-last level, if there are leaf nodes, must be in the right side of the continuous position.

If the node degree is 1, then the node has only the left child.

The two-tree of the same node tree, the depth of the complete binary tree is minimal.  

Note: A full two fork tree must be a fully binary tree, but a complete binary tree is not necessarily full of two forks.  

The difference between a full two fork tree and a complete binary tree:

full two fork tree is that each layer of leaf nodes are full, and Complete binary Tree is a tree like this: how to put all its n nodes from top to bottom, numbered from left to right, then the corresponding complete binary tree is the same. In other words, a complete binary tree looks like the last few elements of a two-fork tree are removed. This type of two-fork tree has a feature: the node ordinal can be determined to determine the parent-child relationship between the nodes: the two child nodes of the node numbered I are 2*i and 2*i+1, and the number of the node I is the parent node ordinal is I/2 (divisible). So you can save this type of two-tree with an array, so it's easy to operate. For the other two-fork tree, you can transform it into a complete binary tree by filling a special value for those missing nodes. Of course, if there are too many nodes, it is not worth the candle.

The nature of binary tree

Two The nature of a fork tree one : There are at most 2^ (i-1) nodes on the first layer of the binary tree (i>=1) . Two nature of the fork tree two : two fork tree with a depth of K (2^k)-1 nodes (k>=1) Two The nature of the fork tree three : to any one binary tree T, if its terminal node is n0, the degree of 2 of the node is N2, then n0=n2+1

First we assume that the number of nodes with a degree of 1 is N1, then the n=n0+n1+n2 of the nodes of the two-fork-tree T.

Next we find that the number of connections is always equal to the sum of points n-1, and equals n1+2*n2

So n-1=n1+2*n2

So n0+n1+n2-1=n1+n2+n2

Last N0=n2+1

Two properties of a fork tree four : The depth of a complete binary tree with n nodes is : ? log?n?+1 (? log?n? Take Log?n the lower limit)

Proof: by the definition of a full two-fork tree binding property Two we know that the node tree of a full two-tree with a depth of K must be 2^k-1 .

so for a full two fork tree we can get the depth of the full two fork tree by n=2^k-1 backwards to :

K=log? (n+1)

As we have already mentioned in front of the complete binary tree, its leaf nodes will only appear on the bottom two layers, and we can deduce the same as follows

Well, for the second-to-last two-prong tree, we can easily roll it back. The node count is n=2^ (k-1)-1

So the total binary tree node value range is: 2^ (k-1)-1 < n <= 2^k-1

Since n is an integer, n <= 2^k-1 can be seen as n < 2^k

Similarly 2^ (k-1)-1 < n can be seen as 2^ (k-1) <= n

So 2^ (k-1) <= N < 2^k

The logarithm is taken on both sides of the inequality to get k-1<=log?n<k

Since k is depth, it must be rounded, so k=?log?n?+1

Two The nature of the fork tree five : If the nodes of a complete binary tree with n nodes (whose depth is log?n?+1) are numbered by sequence, the following properties are available for any node I (1<=i<=n):

If i = 1, then node i is the root of the two fork tree, with no parents;

If I > 1, is the parent a node? I/2?

if 2i > N, then node I No left child (node i is the leaf node); otherwise its left child is node 2i.

If 2i+1 > N, then node I has no right child, otherwise the right child is a junction 2i+1

Two-fork Tree

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.