In different cases, we perform different searching schemes to find some keys. In this section we will see what are the basic differences between two searching techniques, the sequential search and binary search.
Sequential Search | Binary Search |
---|---|
Time complexity is O(n) | Time complexity is O(log n) |
Finds the key present at first position in constant time | Finds the key present at center position in constant time |
Sequence of elements in the container does not affect. | The elements must be sorted in the container |
Arrays and linked lists can be used to implement this | It cannot be implemented directly into the linked list. We need to change the basic rules of the list to implement this |
Algorithm is iterative in nature | Algorithm technique is Divide and Conquer. |
Algorithm is easy to implement, and requires less amount of code. | Algorithm is slightly complex. It takes more amount of code to implement. |
N number of comparisons are required for worst case. | Log n number of comparisons are sufficient in worst case. |