GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Floyd's Build-Heap performs at most height(v) exchanges while sifting down node v, so its exchanges are bounded by H = Σ height(v) over all nodes (height of a leaf = 0). For a heap of 1000 nodes stored in an array, what is H?
- A. 990
- B. 1013
- C. 994
- D. 992
Correct answer: C. 994
For a heap of n nodes, Σ height(v) = n − (number of 1 bits in n). 1000 = 1111101000₂ has six 1 bits, so H = 994 (confirmed by summing heights directly). 1013 is the value for n = 1023 (n − log₂(n+1)); 990 applies n − ⌈log₂ n⌉.
More Algorithms questions
- A 3-ary min-heap stores 1000 keys in an array A[0..999], with the children of A[i] at 3i + 1, 3i + 2 and 3i + 3. How many of the keys are…
- Computing x¹²⁷ by multiplication, where each step multiplies two powers already computed (squarings count as multiplications), what is the…
- Euclid's algorithm gcd(a, b) repeatedly replaces (a, b) by (b, a mod b) until b = 0, counting one step per mod operation. Over all pairs 1…
- The Sieve of Eratosthenes on 2..100 crosses out the multiples of each prime p ≤ 10, starting from p² (p², p² + p, …). How many numbers are…
- The Tower of Hanoi with 6 disks is played on three pegs in a row (left, middle, right), and a disk may move only between adjacent pegs…
- Of the 92 solutions of the 8-queens problem (rotations and reflections counted separately), how many have no queen on either of the two…