Data structures implemented algorithm code - the binary tree (a)

The basic concept of the tree

Tree structure is a typical non-linear data structure. It seems intuitive hierarchical tree branch relationship is defined (one to many).
1, the definition of the tree

树的定义:树是n(n>=0)个结点的有限集。
(1)当n=0时,称为空树。
(2)当n=1时,有且仅有一个称为根的结点。
(3)当n>1时,有若干个互不相交的子树。

By the above definition, it is a known recursive tree data structure, i.e. the definition of the tree again uses the concept itself (i.e. defined subtree).

2, the tree representation

二元组表示法、广义表表示法、嵌套集合表示法、凸入表示法。详情见教材120页。

3, the tree basic terms:

度、叶子结点、分支结点、双亲、孩子、兄弟、祖先、子孙、层次等有关概念见教材。
注意:一棵树中,结点的总度数等于结点总数减1,也等于总边数(n=k+1)。

Binary Tree

Before discussing the general study of the storage structure and operation of trees, one begins by examining binary tree.

1, the definition of binary tree

二叉树是另一种树形结构,它的特点是每个结点至多有两颗子树(二叉树中不存在度大于2的结点),并且二叉树的子树有左右之分。
显然二叉树也是一种递归的数据结构。

2, five binary form

空二叉树、仅有根结点的二叉树、右子树为空的二叉树、左子树为空的二叉树、左右子树均非空的二叉树。
图形请见教材123页。

3, with full binary tree complete binary tree

Full binary tree:

在一棵树中,若所有的分支结点都有左孩子和右孩子,并且所有叶子结点的层数等于树的深度。
(在不增加树的层数的前提下,无法再添加树的结点的树称为满二叉树)
满二叉树的特点:
    (1)叶子结点只能出现在最下面一层。
    (2)非叶子结点的度都为2
    (3)在相同深度的所有二叉树中,满二叉树的结点个数最多,叶子结点个数也最多。

Complete binary tree:

在一棵二叉树中,除了最后一层外,其余层全满,并且最后一层或是满,或是从最右边缺少若干个连续结点。
(如果只是删除了最底层最右边的连续若干个节点,就称为完全二叉树)
注意:相同结点数的二叉树,不完全二叉树深度最小。

4, 5 important properties of a binary tree for details see textbooks

Published 17 original articles · won praise 21 · views 40000 +

Guess you like

Origin blog.csdn.net/hou1620089770/article/details/46529549