UGC-NET Dec 2014 · Trees

MCQ · 2 marks · Problem PROG-DSTR-0050

Suppose that we have numbers between $1$ and $1000$ in a binary search tree and we want to search for the number $365$. Which of the following sequences could not be the sequence of nodes examined ?
  1. A
    $4, 254, 403, 400, 332, 346, 399, 365$
  2. B
    $926, 222, 913, 246, 900, 260, 364, 365$
  3. C
    $927, 204,913, 242, 914, 247, 365$
  4. D
    $4, 401, 389, 221, 268, 384, 383, 280, 365$

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionDuring the search for 365, a key \(x\) followed by a smaller key means we went left (all later keys must be \(<x\)); followed by a larger key means we went right (all later keys \(>x\)).(A) 4, 254, 403, 400, 332, 346, 399, 365 — every key lies in the current interval, possible.(B) 926, 222, 913, 246, 900, 260, 364, 365 — possible.(C) 927, 204, 913, 242, then 914: after going left at 913 all later keys must be \(<913\), but \(914>913\) — impossible.(D) 4, 401, 389, 221, 268, 384, 383, 280, 365 — possible.Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com