UGC-NET Jul 2016 · Trees

MCQ · 2 marks · Problem PROG-DSTR-0024

Suppose that we have numbers between 1 and 1,000 in a binary search tree and want to search for the number 364. Which of the following sequences could not be the sequence of nodes examined?
  1. A
    925, 221, 912, 245, 899, 259, 363, 364
  2. B
    3, 400, 388, 220, 267, 383, 382, 279, 364
  3. C
    926, 203, 912, 241, 913, 246, 364
  4. D
    3, 253, 402, 399, 331, 345, 398, 364

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

Show the worked solutionWhile searching for 364, each key examined narrows the allowed interval: going left from \(x\) means all later keys are \(<x\); going right means they are \(>x\).(A) 925 (left), 221 (right), 912 (left), 245 (right), 899 (left), 259 (right), 363 (right), 364 — every key stays in its interval, possible.(B) 3, 400, 388, 220, 267, 383, 382, 279, 364 — also stays consistent, possible.(C) 926 (left), 203 (right), 912 (left: now keys must be \(<912\)), then 913 \(>912\) — impossible.(D) 3, 253, 402, 399, 331, 345, 398, 364 — consistent, possible.Answer: C

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