Chapter 6 Tree

1. Definition of tree

Insert picture description here

1.1 Classification of nodes

The subtree owned by a node is called the degree of the node. A node with a degree of 0 is called a leaf node or a terminal node. A node with a
degree of not 0 is called a non-terminal node or a branch node. In addition to root nodes, branch nodes are also called internal nodes. The degree of the tree is the maximum value of the degree of each node in the tree.

1.2 The relationship between nodes

The root of the node's subtree is called the child of the node, and the corresponding node is called the
parent of the child. The children of the same parent are called brothers.
The ancestor of the node is the ancestor of the node from the root to the node. All nodes on the branch.

1.3 Other related concepts of trees

The level of the node starts from the root node, the root is the first level, and the children of the root are the second level.
The maximum level of the node in the tree is called the depth or height of the tree. The
forest is m (m>=0). Collection of intersecting trees

2. Tree storage structure

Parental representation: In each node, an indicator is attached to indicate the position of its parent node in the array.
Child representation: Arrange the children of each node and use a singly linked list as a storage structure, then n children There are n child linked lists, if it is a leaf node, the secondary singly linked list is empty. Then n head pointers form a linear list, which is stored in a sequential storage structure and stored in a one-dimensional array.
Child brother notation: we set two The pointers point to the first child of the changed node and the right brother of this node.

3. Binary tree

There are special binary trees such as oblique trees, full binary trees, and complete binary trees.

3.1 The nature of binary trees

Property 1:
Insert picture description hereProperty 2:
Insert picture description hereProperty 3: For any binary tree T, if its terminal node is n0 and the number of nodes with degree 2 is n2, then n0=n2+1
Property 4: Insert picture description here
Property: 5
Insert picture description here

3.2 The storage structure of the binary tree

Sequential storage structure
Binary linked list

3.3 Traverse the binary tree

Pre-order traversal
Middle-order traversal
Post-order traversal
Layer sequence traversal

3.4 Thread Binary Tree

The pointers to the predecessor and successor are called clues, and the binary linked list with clues is the clue linked list, and the corresponding binary tree is called the clue binary tree.

4. Conversion of forest tree and binary tree

Convert a tree to a binary tree 3 steps to add lines to adjust the level of the
forest to a binary tree 2 steps to convert each tree to a binary tree, starting from the second one, in turn, use the root node of the second binary tree as the right child of the previous binary tree, and connect them with lines .

Huffman tree and its application

The compressed package uses Huffman coding.

Guess you like

Origin blog.csdn.net/mogbox/article/details/109401242