Nonlinear hierarchical structure - trees (binary logical structure) 02

The logical binary tree structure

Binary tree is a high storage efficiency when using chain configuration storage, is the simplest form of a tree, and therefore focus on characteristics, storage and computing a binary tree.

Question: how to convert binary tree with the tree?
Here Insert Picture Description

1. The binary tree into

The conversion process:

Plus line: adding a connection between all adjacent sibling nodes.
To line: for each non-terminal node, in addition to its leftmost child node by deleting the connection with other children nodes.
Rotation: the root node to the axis of rotation to the right 45 °.
Adjustment: organized into a binary tree.
Here Insert Picture Description

Tree into a binary tree during contact each node what kind of change?

Discussion: The process plus line is directly related to the increase taking point and brothers;
operation to the line, is to remove the links in addition to the eldest son, but by brotherhood eldest son, indirectly, all the child's information, the previous introduction of "tree chain store - child brother representation" is the same principle.

2. The forest is converted to a binary tree

Transformation: respectively, the forest each tree into a binary tree.
Connections: from the last binary tree, turn to the root of the binary tree as the right child of the root node of a binary tree before, until all the binary trees are connected, and then organized into a binary tree.
Here Insert Picture Description

3. Restore binary tree

Plus line: If a node x is y's left child of its parents, children and grandchildren put the right node x and node y are linked up with the line.
Go line: delete the original binary connection nodes in all of the parents and the right child node.
Adjustment: organize tree or forest from the above two steps obtained make it structured.
Here Insert Picture Description
Tree reduced to a binary tree during contact each node what kind of change?

X a left child node of its descendants, the origin point of view, this is the left child of the brother, as shown in FG 5.24 points, are descendants of E, the children of the EFG is B, it is added to restore the junction line point relationship with the child; to remove the line is the connection between the brothers, so that you can return to the original structure of the tree.

4. Relationship to store binary tree of

一棵树采用孩子兄弟表示法所建立的存储结构,与它所对应的二叉树的二叉链表存储结构是完全相同的,只是两个指针域的名称及解释不同而已,图(c)中,结点 C 是结点 B 的右兄弟,而图(e)中,结点 C 是结点 B 的右孩子。因此,二叉链表的有关处理算法可以很方便地转换为树的孩子兄弟链表的处理算法。
Here Insert Picture Description

二叉树的概念

1.二叉树的定义

二叉树是n(n≥0)个结点的有限集,它或为空树(n=0),或由一个根结点和两棵分别称为左子树和右子树的互不相交的二叉树构成。

说明:二叉树是每个结点最多有两个子树的有序树。二叉树的子树通常称为“左子树”(left subtree)和“右子树”(right subtree)。左、右子树的顺序不能互换。

二叉树与树的区别是什么?

讨论:尽管二叉树与树有许多相似之处,树和二叉树的两个主要差别:
(1)树中结点的最大度数没有限制,而二叉树结点的最大度数为2;
(2)树的结点无左、右之分,而二叉树的结点有左、右之分,
Here Insert Picture Description
2.二叉树的各种形态

五种基本形态
Here Insert Picture Description

二叉树的特殊形态—— 满二叉树(Full Binary Tree)
Here Insert Picture Description

二叉树的特殊形态——完全二叉树
Here Insert Picture Description

完全二叉树的描述:先给满树编号,根结点编号为1,从根开始自顶向下,自左至右,结点连续编号,在去掉若干结点后,如果树的编号依然连续,则是完全二叉树。
Here Insert Picture Description

二叉树的基本性质

Here Insert Picture Description
证:n0=n2+1

设二叉树上结点总数:n=n0+n1+n2
又二叉树上分支总数:b=n1+2*n2
而 b=n-1=n0+n1+n2-1(减去上面没有连线的结点)
因此,n0=n2+1
Here Insert Picture Description
【例1】二叉树各种结点数目的计算

若一个完全二叉树有n=1450个结点,则度为1的结点、度为2的结点、叶子结点个数分别是多少?有多少左孩子,多少右孩子?该树的高度是多少?

解:树的高度 h =[log n]+1=11

Tree height: ∵ is complete binary tree ∴ 1 ~ 10 layers are full, k = 10

The number of the lowermost leaf node = n- (2 ^ k -1) = 1450-1023 = 427

k-1 layer tape leaves of nodes = [(427 + 1) / 2] = 214

k-1 layer nodes = 2 ^ (k-1) = 512

k-1 layer leaf count = 512-214 = 298

∴ Total leaf n0 = 427 + 298 = 725

2 the degree of the node n2 = n0-1 = 724

1 degree node n1 = n1 - 2n2 = 1450-1-2 * 724 = 1

There are left child is the number of nodes = the number of nodes of degree 2 + 1 = number of nodes 725

Children have the right degree of nodes = the number of nodes 2 = 724

.
.

Binary operation defined

Here Insert Picture Description

Published 26 original articles · won praise 3 · Views 1471

Guess you like

Origin blog.csdn.net/herui7322/article/details/104169201