GATE Computer ScienceHardGATE CS (PYQ pattern)
A 3-ary max-heap with 100 elements is stored in a 0-indexed array (the children of i are 3i + 1, 3i + 2, 3i + 3). How many leaves does it have, and how many children does the last internal node have?
- A. 66 leaves, 2 children
- B. 67 leaves, 3 children
- C. 67 leaves, 1 child
- D. 50 leaves, 3 children
Correct answer: B. 67 leaves, 3 children
The parent of the last index 99 is floor((99 - 1) / 3) = 32, so indices 0 to 32 are internal and the other 100 - 33 = 67 are leaves. Node 32's children are 97, 98 and 99, all present, so it has 3 children (the binary-heap habit of n/2 gives 50).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Build-heap (bottom-up, max-heap) is run on [3, 9, 2, 1, 4, 5, 8, 7, 6, 10, 12, 11]. In each sift-down step the larger of the element and…
- A dynamic array starts with capacity 4. When an append finds it full, it allocates capacity c + c / 2 (integer division), copies every…
- The words tea, ten, to, inn, in, i, ted, tent, tenant, tens, ton are inserted into an initially empty trie (one node per character, root…
- An array A[-2..5][1..6][0..3] of 4-byte elements has base address 1000 (address of A[-2][1][0]). What is the address of A[3][4][2] in…
- Only the non-zero band of a 20 x 20 tridiagonal matrix (entries with |i - j| <= 1, rows and columns numbered from 1) is stored in a 1-D…
- void f(int n) { if (n <= 1) return; f(n - 1); f(n / 2); } Each activation record takes 32 bytes. What is the peak stack usage in bytes…