Some properties of two-fork tree

Source: Internet
Author: User
Introduction to the tree

1. Definition of tree

A tree is a data structure that consists of n (n>=1) finite nodes that form a set of hierarchical relationships.

It's called a "tree" because it looks like an upside down tree, which means it's rooted and the leaves are facing down. It has the following characteristics:
(01) Each node has 0 or more child nodes;
(02) A node without a parent node is called a root node;
(03) Each non-root node has and only one parent node;
(04) In addition to the root node, each child node can be divided into more than one disjoint subtree.

2. Basic terminology of Trees

If a node has a subtree, the node is called the "parent" of the Zishugen, and the root of the subtree is the "child" of the node. The nodes with the same parents are "brothers" to each other. Any node in the subtree of a node is descended from that node. All nodes from the root node to the path of a node are the ancestors of that node.

the degree of the node: the number of subtrees owned by the node.
leaf : A node with a zero degree.
Branch node : A node with a Non-zero degree.
the degree of a tree: the maximum degree of a node in a tree.

level : The level of the root node is 1, the rest of the node is equal to the level of the parent node of the node plus 1.
height of the tree : The maximum level of nodes in the tree.
unordered Tree : If the order between the nodes in the tree is unimportant, you can swap positions.
ordered Tree : If the order between the nodes in the tree is important, the position cannot be exchanged.
Forest : consisting of 0 or more disjoint trees. Add a root to the forest, the forest becomes a tree, and by deleting the root, the tree becomes the forest.

introduction of two fork tree

1. Definition of two fork tree

A binary tree is a tree structure with a maximum of two subtrees per node. It has five basic forms: the two-fork tree can be an empty set, the root can have a left subtree or right subtree, or both the left and right subtrees are empty.

2. The nature of the two-forked tree

The binary tree has the following properties: TODO (superscript and subscript)
Nature 1: two fork tree the number of nodes on layer i is 2{i-1} (i≥1).
Property 2: The two-fork tree with a depth of K has at most 2{k}-1 nodes (k≥1).
Property 3: The height of the two-fork tree containing n nodes is at least log2 (n+1).
Property 4: In any binary tree, if the number of terminal node is n0, the degree of 2 of the knot point is n2, then n0=n2+1.

2.1 Property 1: Two fork tree the number of nodes on layer I is 2{i-1} (i≥1)

Proof: The following use "mathematical induction" to prove.
(01) When I=1, the number of nodes in layer I is 2{i-1}=2{0}=1. Because there is only one root knot on the 1th floor, the proposition is set up.
(02) Suppose that when i>1, the number of nodes in layer I is 2{i-1}. This is inferred from (01).
Based on this assumption, we infer that the number of nodes in the i+1 layer is 2{i}.
Since there are at most two children in each node of the binary tree, the number of nodes on the "i+1" layer is "up to twice times the number of nodes on the first tier". That is, the maximum number of nodes on the (i+1) layer is =2x2{i-1}=2{i}.
Therefore, the hypothesis is established, the original proposition can be verified.

2.2 Property 2: Two fork trees with a depth of K at most have 2{k}-1 nodes (k≥1)

Proof: In a two-fork tree with the same depth, when each layer contains the maximum number of nodes, the nodes in the tree are the most. Using "Nature 1", the number of nodes in the two-tree with a depth of K is at most:
20+21+...+2k-1=2k-1
So the original proposition to get proof.

2.3 Property 3: The height of the two-fork tree containing n nodes is at least log2 (n+1)

Proof: According to the "Nature 2", the height of H-two-fork tree has 2{h}–1 nodes at most. Conversely, the height of a two-fork tree containing n nodes is at least log2 (n+1).

2.4 Property 4: In any binary tree, if the number of terminal node is n0, the degree of 2 of the knot is N2, then n0=n2+1

Proof: Since all nodes in the binary tree are not greater than 2, the total number of nodes (n) = "0 degree knot point (n0)" + "1 degree knot point (N1)" + "2 degree knots (n2)". From this, we get the equation one.
(Equation one) n=n0+n1+n2
On the other hand, 0-degree node without children, 1-degree node has a child, 2-degree node has two children, so the number of children in the binary tree node is: n1+2n2. In addition, only the root is not a child of any knot. So the total number of nodes in the binary tree can be expressed as equation two.
(Equation two) n=n1+2n2+1
Computed by (equation one) and (Equation two): n0=n2+1. Proof of the original proposition.

3. Full two fork tree, complete binary tree and two fork lookup tree

3.1 Full two fork tree

definition : A height of H, and a two-forked tree of 2{h}–1 nodes, called full two-fork trees.

3.2 Complete Two-fork tree

definition : In a binary tree, only the bottom two levels of the node can be less than 2 degrees, and the bottom of the leaf node is concentrated in a number of positions on the left. Such a two-fork tree is called a complete binary tree.
features : leaf nodes can only be present at the lowest and second lower levels, and the lowest leaf nodes are concentrated in the left part of the tree. Obviously, a tree full of two forks must be a completely binary tree, and the complete binary tree is not necessarily full two fork tree.

3.3 Two fork lookup tree

definition : Two-fork Lookup tree (Binary), also known as a binary search tree. Set X to a node in the two-fork lookup tree, where x nodes contain key keys, and the key value of Node x is recorded as Key[x]. If Y is a node in the left subtree of x, then key[y] <= key[x]; if Y is a node of the right subtree of x, Key[y >= key[x].

In the binary lookup tree:
(01) If the left subtree of any node is not empty, the value of all nodes in the left subtree is less than the value of its root node;
(02) The right subtree of any node is not empty, the value of all nodes in the right subtree is greater than the value of its root node;
(03) The left and right subtree of any node is a two-fork lookup tree, respectively.
(04) There is no node with equal key value (no duplicate nodes).

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.