Calculate the worst-case time complexity of searching for an element in a singly linked list
Calculate the worst-case time complexity of searching for an element in a singly linked list
with 'n' elements.
Show answerHide answer
Correct answer: (B) O(n)
Explanation
A linked list must be traversed node by node from the head. In the worst case the key is the last node or is missing, which needs n comparisons, so the time is O(n).