Linear Search
Linear Search
Int arr[9] [0] [1] [2] [3] [4] [5] [6] [7] [8]
33 55 88 77 44 11 66 22 99
1) Get the key from the user. Key = 11 Average Case time Complexity
2) Start traversal from the 1st element(0th index). Big theta (n)
Key found at index 5 O(n/2) --> O(n) --> (as 1/2 is
3) Compare the key with each element. Comparisons = 6 constant and hence discarded)
a. If the key is found, return the index.
b. Else, continue the search till the last element.
Key = 33 Best Case Time Complexity
Key found at index 0 O(1) --> Order Of (1) Big Omega(1)
Comparisons = 1