Binary search tree supports many dynamic collection operations, which can be used as a dictionary or as a priority queue.
The time cost of the basic operation of the binary search tree is proportional to the height of the tree, log n level. The expected height of a randomly constructed two-fork search tree is log n.
Each node contains information: Key, satellite data, parent, left child, right child.
12.1 Two Fork Search tree definition:
Left dial hand tree is less than node, right subtree is greater than node.
All keys can be output recursively using the middle order traversal, and the traversal time is O (n)
12.2 Query Binary search tree
The most common operation: Find a specific key,
Additional operations: Successors, precursors, maximums, minimums, all O (h), H is the height of the two-fork search tree.
Find default starts from the root node.
A successor refers to an element that is only larger than its predecessor, which refers only to the element that is smaller than it.
12.3 Inserting and deleting
Inserting elements is simple, and finding the right location is OK.
Deleting elements is difficult,
If you don't have children, you can simply delete them.
If there is only one child, it is OK to connect the children with the father.
If there are two children, first remove its successor,
12.4 randomly constructed two-fork lookup tree
To construct a two-fork search tree: Always insert elements,
The desired height is logn.
Expected complexity of NLOGN
"Introduction to Algorithms" chapter 12th, Binary search tree