Data Structure Tree Notes-1

tree structure _

Be familiar with the structure of trees , structure determines properties , properties determine use

1. A tree  is a tree -like hierarchy

2. From the point of view of the definition method, the tree is a recursive definition method, because each node can be used as the root node to give birth to children. 

A tree has only one root,

But there can be multiple root nodes, as long as there are child nodes, then this node is a root node, so all other nodes except leaf nodes are a root node

3.   One (this node as the root node) to many (children):

Immediate Precursor - Father Node

direct successor - child node

The root of the tree has no direct predecessor and can have multiple direct successors;

A leaf node has a direct predecessor and no direct successor;

Except for the rest of the root node and leaf node , there is one direct predecessor, and there can be multiple direct successors;

Because there are nodes with direct predecessors, there can only be one predecessor (each child has only one parent), so the tree does not cross

4.  The data type of each node is the same, and the node stores not only data elements , but also pointers / branches to subtrees

 

Basic concepts and terminology of trees

The degree of the node ( degree ) - the number of branches of this node as the root node / the number of direct successors / the number of children

The degree of the tree - the max value of the degree of the nodes in the tree

Leaf node - a node with a node degree equal to 0

Branch node - a node with a node degree greater than 0. Naturally, the rest of the nodes except the leaf node are branch nodes

Node path - branches and nodes from the root of the tree to this node

The level of the node - the level of the root node is 1 , the number of levels of the remaining nodes = the number of branches in the node path + 1

The depth of the tree - the maximum value of the node level. So it can only be the hierarchical value of a leaf node.

 

Definition of a binary tree

A binary tree is a type of tree, based on the tree, it is more strictly limited in structure:

1.  Each node has a maximum of 2 forks / branches; the number of ordinary tree branches is not limited

2.  The left fork and the right fork are forks , and the equivalent statement is that the children are divided into left children and right children ; ordinary trees do not record the order of children.
   Based on the structure of the tree and the characteristics of the binary tree, it can be known that the binary tree has a total of 5 basic forms , which are:

a.  Empty tree

b.  There is only one root node

c.  The root node + the left subtree derived from the root, there is no right subtree

d.  Tree root node + right child derived from tree root, no left child

e.  Tree root node + left child derived from tree root + right child derived from tree root

Brainstorm :

What are the different forms of a binary tree with 3 nodes?
Think of it this way:
A tree with 3 nodes can have up to 3 levels

Draw a 3 -level full binary tree (a binary tree with as many nodes as possible at each level), and then construct

——绿 + 红(1种)

——绿 + /黄(2种)

——红 + /灰(2种)

所以,有5种形态的二叉树

可是能把上述人脑思考的过程用算法表达出来么?

在这里我遇到了这个问题,于是我停下来关上电脑,打算在纸上想想如何用程序实现。

那我们就下次见。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324816229&siteId=291194637