GATE | GATE-CS-2002 | Question 5
In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is
(A) log2 n
(C) log2n – 1
Explanation: Singly linked list has uni – directional flow, i.e., it has only one pointer for moving (the next pointer).
In the worst case, for searching an element in the singly linked list, we will have to traverse the whole list (the case when the required element is either the last element or is not present in the list).
So, in the worst case for a list of length n, we will have to go to each node for comparison and thus, we would be needing ‘n’ comparisons.
Thus, D is the correct choice.
Please comment below if you find anything wrong in the above post.
Quiz of this Question
Please Login to comment...