Data structure full two fork tree and complete binary tree difference __ data structure

Source: Internet
Author: User
There are a lot of binary tree categories, of which the full two fork tree and the complete binary tree is very special, because these two kinds of two-fork tree efficiency is very high, here records a few related properties.

The first is full of two fork tree: from the image of the full two fork tree is an absolute triangle, that is, its last layer is all leaf nodes, the remaining layers are all non-leaf nodes, if the mathematical formula is expressed by the number of nodes n=2^k-1 which K is the depth, that is, the number of layers. That is, the number of nodes full of two tree is a series of fixed number, for example, 1,3,7,15 ... if the number of nodes is not the number in this sequence, then he certainly is not full of two fork tree, of course, and vice versa, is also established.

Because of its number of nodes and the shape of the fixed, we can find a lot of its mathematical formula properties.

The first is the relationship between the number of nodes and the depth n=2^k-1

The second is that the number of nodes on layer i is 2^ (i-1)

The third is to give all the node number (starting from 1th instead of starting from 0th), for a node numbered I we can determine whether he is the left node or the right node, who is the parent node, who is the child node, according to the size of I. For example, we give a number 13 node, then he is odd so he is the right node, because the node changes and the parity of the data is a synchronous change. His parent node is 13/2=6 (starting from number 1th) his left child node is the 13*2=26 right child node is 13*2+1=27 also can beg his brother node, parent node,

All in all, as long as there is a number of a node in the two-fork tree, then his position in the entire binary tree is determined, and it is for this reason that we prefer to use a sequential structure rather than a chain structure to store a full two-fork tree.

However, since the number of nodes full of two forks must be a definite number, not an arbitrary number, its use is subject to certain limitations, and in order to break the other limit, we define a special two-fork tree-a fully binary tree.

The number of nodes in a complete binary tree is arbitrary, in form it is a possible missing triangle, but the missing part must be a continuous part of the lower right corner. This is not complete, more accurately, we can say that it is the difference with a two-fork tree is that its last line may not be complete, but is definitely the right of the continuous partial missing. May sound a bit chaotic, in the mathematical formula, for the K-layer of the complete binary tree, its node number range is 2^ (k-1) -1<n<=2^k-1;




A two-prong tree with a depth of K and 2 minus 1 nodes is a full two-fork tree.
A two-tree with a depth of k, with n nodes, is called a complete binary tree when the search for 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.
1 1
/     \                          /      \
1 1 1 1
/    \    /    \                  /     \
1 1 1 1 1 1
Full two fork tree complete binary tree




*************************************************************************************************************** *************************************************************************************************************** ************************
Two-fork Tree:
is a finite set of n (n>=0) nodes, which is either an empty tree (n=0), or a root node and two two-fork trees, called Saozi right subtrees, which are disjoint respectively.

Full two fork tree:
A two-fork tree with a depth of K and a 2^k-1 node is called a full two-tree.
All nodes except the leaf node have two child nodes. The number of nodes reaches the maximum value. All leaf nodes must be on the same layer.

Complete binary tree:
If the depth of the two-fork tree is H, except for the H layer, the number of nodes in each layer (1~H-1) reaches the maximum number, and the node in the H layer is continuously concentrated on the leftmost side, which is the complete binary 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.