GATE Computer ScienceVery hardGATE CSE
A max-heap is built from the array [3, 9, 2, 1, 4, 5, 8, 7, 6, 10] using the bottom-up procedure (sift-down from index ⌊n/2⌋−1 to 0, children of i at 2i+1 and 2i+2, 0-indexed). How many element swaps are performed in total?
- A. 6
- B. 7
- C. 8
- D. 10
Correct answer: B. 7
Sifting down from nodes 4,3,2,1,0 in turn; the resulting heap is [10, 9, 8, 7, 4, 5, 2, 1, 6, 3] after 7 swaps.
More Algorithms questions
- A hash table of size 11 uses double hashing with h1(k) = k mod 11 and h2(k) = 7 − (k mod 7), probing slot (h1 + i·h2) mod 11 for i = 0, 1…
- How many distinct spanning trees does the complete bipartite graph K(3,4) have?
- Floyd–Warshall is run on a 5-vertex digraph (vertices 0..4) with arc weights 0→1:3, 0→3:7, 1→0:8, 1→2:2, 2→0:5, 2→3:1, 3→0:2, 3→4:4 (no…
- In how many ways can a longest strictly increasing subsequence be chosen (counting index sets, not distinct value sequences) from the…
- Randomised quicksort picks the pivot uniformly at random from the current sub-array and each partition of m elements uses exactly m−1…
- Bellman–Ford from source 0 on vertices 0..5 relaxes the directed edges (u→v, w) in this fixed order in every pass: 4→5 (1), 3→4 (1), 2→3…