Open In App

GATE | GATE-CS-2002 | Question 5

Like Article
Like
Save Article
Save
Share
Report issue
Report

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
(B) n/2
(C) log2n – 1
(D) n

Answer: (D)
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


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads