Based on“Data Structures and Algorithm Analysis Edition 3.2 (C++ Version)” from C. A. Shaffer
Basic Searching Algorithms
Linear Search (Sequential Search)
The simplest searching algorithm, Perfromance O(n).
Binary Search
A binary search halves the number of items to check with each iteration, so locating an item (or determining its absence) takes logarithmic time, performance O(log n)
Interpolation search
In each interpolation search step, it calculates where in the remaining search space the sought item might be, based on the key values at the bounds of the search space and the value of the sought key, usually via a linear interpolation:
Block Search
Block search refers to a search algorithm for ordered lists. It works by first checking all items
Binary Search Tree
Property
All elements stored in the left subtree of a node with value K have values < K. All elements stored in the right subtree of a node with value K have values >= K.
Operations
Traversal
To visit BST nodes in sorted order from lowest to highest, just need to do inorder traversal.
Search
Start from the root node, if greater than what you want, go search left subtree; if less than what you want, go search right subtree, until you find the value you want.
Insert
Start from the root node, if greater than what you want, go search left subtree; if less than what you want, go search right subtree, until there is no subtree. Then creat a leaf node with the new value.
Remove
If it’s a leaf node, just delete it; if it’s an internal node with only one child, just let it’s child be it’s parent’s child, then delete the node ; Else, replace the value you want to delete with the smallest value in the right subtree(that is, the leftest value in the right subtree), then remove the leftest node in the right subtree.
Performance
For search, insert and remove operations, the costs are all