What is the worst-case time complexity of search operation on unordered and…
2022
What is the worst-case time complexity of search operation on unordered and ordered list using linear search algorithm respectively?
- A.
O(n) and O(1)
- B.
O(n) and O(log n)
- C.
O(n) and O(n)
- D.
O(log n) and O(log n)
Attempted by 182 students.
Show answer & explanation
Correct answer: C
Using linear search : 1️⃣ Unordered list: You may need to check every element in the worst case. ➡ Worst-case time = O(n) 2️⃣ Ordered list: Even though the list is sorted, linear search still checks elements one by one until the key is found or list ends. ➡ Worst-case time = O(n) Thus for unordered and ordered lists respectively: ➡ O(n) and O(n)