Searching Algorithms
Contents
Linear Search
Searches from 0 to n-1 (linearly)
Time Cost: O(n)
|
|
Linear Search (ordered data)
Searches from 0 to n-1 (linearly)
if (x > array[i]) break;
|
|
Binary Search (ordered data)
- divide and conquer
- start at the middle; and we can check which side to continue checking
best case: t(n) ~ O(1)
worst case: t(N) = 1 + t(N/2) = log2(N) + 1 ~= O(log N)