Basic data structures - binary tree

Binary Tree

  • Depth of the tree is O (log n)
  • Has left child, right child
  • Full binary tree, each branch are full
  • Complete binary tree, remove some of the nodes by following the expiration of a binary tree, ensure that the last node before the node is complete
  • An array or linked list may be represented using

When using binary array positioning method

N the current node
left child 2 n + 1
right child 2
n + 2

Conversely, the current node is the left child of its parent node, the parent node (n-1) / 2; right child, the parent node (n-2) / 2

Application Binary Tree

Binary search tree (binary sort tree), the root node is greater than the left child, right child of less than
1. Find
sequentially starting from the root comparison, similar binary search, so the complexity of O (log n)

2. maintain the relative order
according to the size of data inserted

Traversing Binary Tree

1. depth-first

  • prologue
  • In order
  • After the sequence
    for use iteration or also has a "backtracking" attribute of the stack to write code

2. Breadth-First

  • Traversal sequence
    for use queue write

Guess you like

Origin www.cnblogs.com/j-c-y/p/11544008.html