What is the worst-case time complexity of searching for an element in an…
2024
What is the worst-case time complexity of searching for an element in an unsorted linked list ?
- A.
O(1)
- B.
O(log n)
- C.
O(n)
- D.
O(n2)
Attempted by 215 students.
Show answer & explanation
Correct answer: C
To search for an element in an unsorted linked list, we must traverse the nodes sequentially from the head. Since the list is unsorted, there is no way to predict where a specific value might be located or skip any nodes. In the worst-case scenario, the target element is either at the very end of the list or not present at all. This requires visiting every single node in the sequence exactly once to confirm its absence or find it.",