Comparison of linear and binary search algorithms by the number of comparisons
Examples
| # |
Line Search |
Binary Search |
| 2 |
2 |
2 |
| 16 |
16 |
5 |
| 1024 |
1024 |
11 |
| 1048576 |
1048576 |
21 |
The advantage of binary sort is that it is faster.
Cons- a pre-sorted array is required.