0% found this document useful (0 votes)
1 views

Linear Search

Uploaded by

vaidyapranjali9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Linear Search

Uploaded by

vaidyapranjali9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Linear Search

03 October 2024 14:17

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

Key = 99 Worst Case Time complexity Big Oh(n)


For(i=0; i<9; i++) Key found at index 8 O(n) --> Order Of (n) --> n
{ Comparisons = 9 is the number of elements
If(key == arr[i]) in an array
Return I;
}
Key = 120 Worst Case time
Key not found Big Oh(n)
Complexity
Comparisons = 9 O(n) --> Order of(n)

Linear Search Page 1

You might also like