Data Structures and Algorithms abbreviated - Binary Tree

Binary Tree (Binary Tree)


 

tree

  • Root, parent, sibling, leaf nodes
  • Concept of height, depth, layer

Binary Tree

As the name suggests, each node has at most two "forks", that is, two children, were left child and right child nodes, the nodes are not required to have to have two, some only left node, some only the right node

Full Binary Tree

  • FIG binary numbers, the leaf node are all in the bottom 2, except leaf nodes, each node has left and right child nodes, is called a full binary tree to a binary tree that

Full Nimata 树

  • FIG binary numbers, the leaf node 3 in the bottom two layers, the last layer of the left leaf node are arranged, and except for the last one, the number of nodes other layers have reached the maximum, which is called complete binary tree binary Tree

How to represent (or store) a binary tree?

  • Chain store law
  • Method sequential storage
    • Array-based
    • If node X is stored in the array index of position i,
    • 2 * i is the index of the storage location is left child,
    • The subscript is the right child of the stored position of the 2 * i + 1.
    • In turn, the position storage labeled i / 2 is its parent node. In this way, as long as we know the position of the root node stored (in general, in order to facilitate the calculation of child nodes, the root node is stored at an index position 1), so can be calculated by the following standard, the whole tree are strings stand up.
    • Suitable for complete binary tree , if a non-complete binary tree would be a waste of space;
    • Heap is a complete binary tree, and are often used to store data array

Binary tree traversal

  • Preorder traversal - Access sequence: parent - "left child -" right child
  • Preorder - access order: left child - " parent -" right child
  • Postorder - access order: left child - "the right child -" the parent node

Binary search tree (Binary Search Tree)

 

Guess you like

Origin www.cnblogs.com/wod-Y/p/12024384.html