GATE Computer ScienceModerateGATE CS (PYQ pattern)

A BST is built from the sorted array 1, 2, ..., 14 by recursion: the root is a[mid] with mid = (lo + hi) / 2 (integer division), then the left half and the right half are built the same way. What is the preorder traversal?

  1. A. 8 4 2 1 3 6 5 7 12 10 9 11 14 13
  2. B. 1 2 3 4 5 6 7 8 9 10 11 12 13 14
  3. C. 7 3 1 2 5 4 6 11 9 8 10 13 12 14
  4. D. 14 12 13 10 8 9 11 6 4 5 2 1 3 7

Correct answer: C. 7 3 1 2 5 4 6 11 9 8 10 13 12 14

mid of [0..13] is 6 (key 7); left half [0..5] has mid 2 (key 3) and right half [7..13] has mid 10 (key 11). Continuing gives 7 3 1 2 5 4 6 11 9 8 10 13 12 14.

More Programming and Data Structures (GATE) questions

Exams that ask this topic