Skip to content
Official PYQ · 2002

GATE CS 2002 Q1.5 — Linked Lists

Explain with AI

In the worst case, the number of comparisons needed to search a single linked list of length nn for a given element is

Choose one option
View worked solution

Answer: D

In a singly linked list, elements are accessed sequentially starting from the head node because there is no direct indexing (random access) available.

To search for a target element in a singly linked list of length nn:

  • Best Case: The element is at the first position (head of the list), requiring 11 comparison.
  • Average Case: The element is located somewhere in the middle, requiring approximately n2\frac{n}{2} comparisons on average.
  • Worst Case: The element is either at the very end of the list (the nn-th node) or is not present in the list at all. In this case, we must traverse and compare all nn elements.

Thus, the number of comparisons needed in the worst case is nn.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Linked Lists questions