GATE Computer ScienceHardGATE CS (PYQ pattern)
Keys 50, 30, 70, 20, 40, 60, 80, 10, 35, 45, 65, 85, 5, 15, 32, 38, 90 are inserted in this order into an empty BST (root at depth 0). Number the positions of each level as in a heap (root 1, children of p at 2p and 2p + 1), and define the width of a level as (largest position - smallest position + 1), counting the empty places in between. What is the maximum width and the depth at which it first occurs?
- A. 5 at depth 3
- B. 16 at depth 4
- C. 8 at depth 3
- D. 16 at depth 3
Correct answer: B. 16 at depth 4
Positions per level (depth 3: 10 at 8, 35 at 10, 45 at 11, 65 at 13, 85 at 15; depth 4: 5 at 16, 15 at 17, 32 at 20, 38 at 21, 90 at 31). Depth 3 spans 8 to 15, width 8; depth 4 spans 16 to 31, width 16. Counting only the nodes present gives the maximum 5 at depth 3, which is a different measure.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A min-heap is built from [27, 5, 19, 3, 41, 8, 16, 2, 33, 11, 24, 7] by bottom-up heapify, and then extract-min (last element to the root…
- int m[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; for (int i = 0; i < 4; i++) for (int j = 0; j < i; j++) {…
- A routine reverses the entire string in place and then reverses each maximal run of non-space characters in place. It is applied twice in…
- A singly linked list 1 -> 2 -> ... -> 20 undergoes two passes: first every 3rd node (by current position) is deleted, then in the…
- int x = 1; int inc(void) { return x += 1; } int dbl(void) { return x = 2; } int sq(void) { return x = x; } int (fp[3])(void) = {inc, dbl…
- A table of size 13 uses double hashing, probe i of key k is (k mod 13 + i (1 + k mod 11)) mod 13. Keys 18, 41, 22, 44, 59, 32, 31, 73 are…