Data Structure Tree

1. Tree

1.1 Basic idea

Tree is an abstract model of hierarchical structure

  • A tree is composed of nodes in a parent-child relationship

    • Often change time from space
    • Depends on the sorting of elements, which means the sorting of memory blocks
  • Tree term

    • Root: no parent node
    • Internal node: A node with at least one child node
    • External node: no child nodes
    • Ancestor of node: parents, grandparents, etc.
    • Descendant of a node: child, grandson, great-grandson, etc.
    • Depth of a node: The number of ancestor heights of the tree: the maximum depth of any node
    • Height: the maximum depth of any node
    • Sibling: brothers and sisters
    • Subtree: The tree is composed of nodes and descendants
    • Edge of tree: a pair of nodes (u, v), u is the parent node of v
    • Path: A sequence of node ST, from any two consecutive nodes on the edge
A
B
C
D
E
F
G
H
I
J
K
  • Tree ADT

    • Binary tree data can be realized by storing one node plus two sub-pointers
    • Trees with more than two children can be implemented using a list of nodes in a linked list
  • Traverse pre

  • Post-order traversal: the node is visited after its descendants

  • Sequential traversal: visit the node inorder before the left subtree and the right subtree

1.2 Binary tree

1.3 Binary search tree

Guess you like

Origin blog.csdn.net/weixin_44127327/article/details/108323806
Recommended