Two-fork Tree

Source: Internet
Author: User

1, the definition of binary tree

The binary tree of----is a finite set of n (n>=0) nodes. When N=0, the set is empty (called an empty binary tree ) and, conversely, a non-empty binary tree.

A non-empty binary tree consists of a root node and a two- left dial hand tree of two disjoint, respectively called root nodes, and a right subtree .

----Binary tree has all the basic characteristics of tree structure. A binary tree is often used as a two-fork search tree and a two-fork heap or a two-fork sort tree .

2. Characteristics of two-fork tree

--1) Each node has a maximum of two subtrees trees , so there are no nodes in the binary tree that are more than 2. Note that there are not only two subtrees trees, but at most.

It is possible to have no subtrees or a subtrees tree.

--2) The right sub-tree of Saozi is ordered, and the order cannot be reversed arbitrarily.

--3) Even if there is only one subtrees tree in a tree, it is Zuozi or right subtree to distinguish it. There are two main differences between the----tree and the two-fork tree:

--1) The maximum number of nodes in the tree is not limited, while the maximum degree of the binary tree node is 2;

--2) The nodes of the tree have no left and right points, while the nodes of the binary tree have left and right points. Because the left and right subtree is also a binary tree, it can also be divided into the left and the sub-tree, is recursive.

3, special two-fork tree

----Oblique binary tree

All the nodes are only the left dial hand Tree's two-fork tree called the left oblique tree . All nodes are only right subtree of two fork tree called Right oblique tree . The two are collectively referred to as oblique trees.

Oblique tree has a very obvious feature, that is, each layer has only one node , the number of nodes and the depth of the two-fork tree is the same. The following figure (1) (2) is a diagonal binary tree.

----over two trees

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

Only each branch node has left and right sub-tree, not a full two fork tree, but also must be all the leaves are on the same layer, which will achieve the whole tree balance.

Therefore, the characteristics of the two-fork tree are:

(1) leaves can only be present on the next level . There is no way to strike a balance on the other floor.

(2) The degree of non-leaf junction must be 2, otherwise it is "lack of arms and legs". There is no node with a degree of 1.

(3) in the same depth (depth of K) in the two-fork tree, the number of nodes full two tree 2^k-1 the most, the number of leaves 2^ (k-1) the most .

----Complete binary tree

A two-prong tree with n nodes is numbered in the sequence, if the node numbered I (1<=i<=n) is the node with the same depth in the full two-bit tree, the nodes in the binary tree position

Exactly the same, then the binary tree is called a complete two-pronged tree .

----If the structure of a two-fork tree with n nodes is the same as the structure of the top N nodes of a two-fork tree , such a tree is called a complete binary tree.

----Full two fork tree must be a completely binary tree, but a complete binary tree is not necessarily a full two-fork tree.

----all nodes of the complete binary tree with the same depth of full two forks, they are numbered in the same sequence as the nodes, which are one by one corresponding. Here's a keyword that is numbered by sequence .

---- The features of the complete binary tree :

--1) The leaf node can only be present on the bottom two levels .

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

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

--4) If the node degree is 1, then the node is only left child, that is, there is no right subtree .

--5) The same number of nodes of the two-fork tree, the depth of the complete binary tree is minimal.

To determine whether a binary tree is a complete binary tree approach: Look at the tree diagram, to each node according to the structure of the full two-tree-level sequence number, if the number appears empty file,

Description is not a complete binary tree, otherwise it is.

4, the nature of the binary tree

--1) There are at most 2^ (i-1) nodes (I>=1) on the first layer of the binary tree.

The first layer is the root node, there is one, 2 of the 0-time side. The second layer has two, 2 1, and so on.

--2) A two-fork tree with a depth of K has at most 2^k-1 nodes (k>=1).

Nodes up to =1+2+4+...+2^ (k-1) are geometric series, based on the geometric series summation formula. (with K, et q=2)

sn=a1 (1-q^n)/(1-Q) =1x (1-2^k)/( -1) =2^k-1

--3) for any binary tree T, if its terminal node (leaf node) number is N0, the degree of 2 of the node is N2, then n0=n2+1.

The terminal node is actually the leaf knot point, a binary tree, in addition to the leaf node, the rest is the degree of 1 or 2 of the knot points , we set N1 for the degree is 1 of the knot points.

The total number of nodes of the tree T is n=n0+n1+n2. And the total number of nodes = The total number of branch +1=n1+2n2+1.

N0+n1+n2=n1+2n2+1--->n0=n2+1

--4) The depth of a complete binary tree with n nodes is [log2n]+1 ([x] = maximum integer not greater than x)

----by the definition of a full two-fork tree: The node of the full two-tree with a depth of K n=2^k-1, K=log2 (n+1) with a full two-fork tree

----for a complete binary tree: Numbered nodes in the full two-tree with the same depth as the sequence number are located exactly in the binary tree.

----The total binary tree node must be less than or equal to two 2^k-1, but must be more than 2^ (k-1)-1. So 2^ (k-1) -1<n<=2^k-1

2^ (k-1) <=n<2^k-->k-1<=log2n<k, and K as the number of degrees is also an integer, so k=[log2n]+1.

--5) If a complete binary tree with n nodes (whose depth is [log2n]+1] is numbered by the sequence (from the first level to the [log2n]+1 layer, each layer from left to right),

root node, if there is a node number I, then its left child node number is 2i, right child node number is 2i+1.

----to any node I (1<=i<=n) has:

----If i=1, the node i is the root of two fork tree, no parent node, if i>1, then its parents node is [I/2].

----if 2i>n, then node I has no left child (node i is the leaf node), otherwise its left child node is 2i.

----if 2i+1>n, then node I do not have the right child, otherwise the right child node is 2i+1.

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.