The time complexity of linear search algorithm over an array of n elements is
A. | O (log2 n) |
B. | O(n) |
C. | O(n log2 n) |
D. | 0 (n2) |
Answer : B Explanation :
Linear search has linear-time complexity; binary search has log-time complexity.
Here is a table that provides some intuition about the running speeds of algorithms
Logarithmic: Linear:
array size | N
--------------------------------------------------------
8 | 8
128 | 128
256 | 256
1000 | 1000
100,000 | 100,000 ....
Binary search and other divide-and-conquer algorithms have logN time complexity; we say O(logN)
Linear search have linear time complexity: O(N). So the option is 'B'
|
|
Option: A Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. |