Please enable JavaScript.
Coggle requires JavaScript to display documents.
Sequential search, Binary Search, i ← i + 1, l ← 0; r ← n − 1, m ←…
Sequential search
Pseudocode of SequentialSearch(A[0..n], K)
-
The algorithm simply compares successive elements of a given list with a given search key until either a match is encountered (successful search) or the list is exhausted without finding a match (unsuccessful search).
If we append the search key to the end of
the list, the search for the key will have to be successful, and therefore we can eliminate the end of list check altogether.
Another straightforward improvement can be incorporated in sequential search if a given list is known to be sorted: searching in such a list can be stopped as soon as an element greater than or equal to the search key is encountered.
Binary Search
Pseudocode of BinarySearch(A[0..n − 1], K)
-
-
-
If they match, the algorithm stops; otherwise, the same operation is repeated recursively for the first half of the array if K < A[m], and for the second half if K > A[m].
Though binary search is clearly based on a recursive idea, it can be easily implemented as a nonrecursive algorithm, too.
-
-
-
-
-
-
-
-