GATE / CS ARCHIVE

GATE CSE 2002 / QUESTION 1.5

Worst-case search in a linked list

Data Structures · Arrays & Linked Lists · Full GATE CSE 2002 paper

GATE 2002, Q1.5 1 mark · MCQ
Report issue

Arrays & Linked Lists

Question 1.5, GATE 2002: How many comparisons are needed in the worst case to find a specified element in a singly linked list with n elements?
(A) log₂ n; (B) n/2; (C) log₂ n − 1; (D) n.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step 1: Identify a worst-case input.

Step 2: Put the target in the final node. Before examining that node, none of the earlier comparisons succeeds, so there are n−1 failed comparisons and one successful comparison. If the target is absent there are n failed comparisons instead. Binary-search logarithmic bounds require positional access and ordering not supplied here; n/2 is not a worst-case bound.

Conclusion: An absent key or a key only at the final node requires examining all n nodes. Each node entails one comparison with the search key, so the worst case is n, D.

Original paper, page 1