Sequential Search
The simplest technique for searching an unordered table for a particular record is to scan each entry in the table in a sequential manner until the desired record is found.
Binary Search
The entries in table are stored in alphabetically or numerically increasing order. The approximate middle entry of the table is located, and its key value is examined. If its value is too high, then the key value of middle entry of first half of table is examined and procedure is repeated on first half until the required item is found. If value is too low, then key of middle entry of second half of the table is tried and procedure is repeated on second half.
Difference of sequential search and binary search
Sequential Search | Binary Search |
It is easy. | It is complicated. |
It needs not to be sorted. | It needs to be sorted. |
To search the last element we have to scan all the elements. | To search the last element we don't have to search all elements. |
If the element is first, then it’s best case bcoz the element is found at first position. | If the element is first, then also we have to check for some of the elements (average case). |