Binary search #
Binary search is half search, and it is effective when the queue list is ordered.
For a list of n elements, binary search requires at mostlOg2nlog2n steps, a simple sequential search requires at most n steps.
log #
Logarithm: The logarithmic operation is the inverse of the exponentiation operation
N=ax(a>0,a≠1)N=ax(a>0,a≠1), xxthat isaabaseNNlogarithm, denoted asx=logaNx=logaN,in:
- aa : end
- NN : Antilogarithm
- xx : byaabaseNNlogarithm of
power:
log refers to both log2log2
log8log8 = log28log28 = 3 (23=823=8)
- The logarithm to the base 10 is called the common logarithm, denoted aslglg
- with irrational numbersee(e=2.71828…e=2.71828…) base logarithm is called natural logarithm, denoted aslnln
- Zero has no logarithm
- In the range of real numbers, negative numbers have no logarithm; in the range of complex numbers, negative numbers have logarithms
Time Complexity #
Practical complexity of simple sequential search O(n)O(n)
time complexity of binary search O(logn)O(logn)
Time complexity represents the worst-case running time
Common time complexity #
- O(logn)O(logn) logarithmic time
- O(n)O(n) linear time
- O(n×logn)O(n×logn)
- O(n2)O(n2)
- O(n!)O(n!) factorial of n