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?
- A. 8 4 2 1 3 6 5 7 12 10 9 11 14 13
- B. 1 2 3 4 5 6 7 8 9 10 11 12 13 14
- C. 7 3 1 2 5 4 6 11 9 8 10 13 12 14
- 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.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- In a binary tree given as (key, left, right) = (10, (-20, (8), (-6, (4), -)), (15, (-3), (12, (7), (-9)))), a 'path' is any sequence of…
- An AVL tree is built by inserting 1, 2, ..., 15 in increasing order (the perfect tree with root 8). Then keys 1, 3, 5, 2, 4 are deleted in…
- Cuckoo hashing uses two tables of size 7: h1(k) = k mod 7 in T1 and h2(k) = floor(k / 7) mod 7 in T2. To insert x, place it in T1[h1(x)]…
- Keys 19, 36, 5, 21, 4, 26, 14, 17, 25, 12, 40, 33 are inserted into a chained hash table with 7 buckets, h(k) = k mod 7, each new key…
- A max-heap is built from [90, 80, 70, 60, 50, 40, 30, 20, 10, 15, 25, 35, 45, 55, 65] by bottom-up heapify. Then the key at index 14 is…
- Two stacks (values and operators) evaluate 12-(3+4(5-2))/53+8/(1+1) with all operators left-associative and integer division truncating…