GATE Computer ScienceVery hardGATE CS
In how many different ways can the 10 distinct keys 1, 2, ..., 10 be arranged in the array positions 1 to 10 of a binary max-heap (each node at index i has children 2i and 2i + 1 and is larger than both)?
- A. 3780
- B. 2520
- C. 3360
- D. 1260
Correct answer: C. 3360
The root must be 10, and the shape of a 10-node complete tree gives a left subtree of 6 nodes and a right subtree of 3 nodes. H(10) = C(9,6) · H(6) · H(3), and H(6) = C(5,3) · H(3) · H(2) = 10 · 2 · 1 = 20 with H(3) = 2, so H(10) = 84 · 20 · 2 = 3360.
More Algorithms questions
- How many binary search trees on the 7 keys 1 to 7 have height exactly 4 (height counted in edges, a single node has height 0)?
- How many times is x++ executed by the following code? for (i = 1; i <= 100; i++) for (j = 1; j <= 100; j += i) x++;
- The array [7, 3, 11, 1, 9, 12, 5, 2, 10, 4, 8, 6] is sorted by merge sort. How many inversions (pairs i < j with a[i] > a[j]) does it…
- A connected weighted undirected graph has vertices 0 to 5 and edges (u, v, weight): (0,1,2), (0,2,2), (1,2,2), (1,3,3), (2,3,3), (2,4,3)…
- A tree has vertices 0 to 9 with edges 0-1, 0-2, 1-3, 1-4, 2-5, 2-6, 4-7, 4-8, 6-9, and vertex weights w0 = 5, w1 = 4, w2 = 6, w3 = 3, w4 =…
- Under the standard uniform-hashing approximations, a table with load factor α = 0.9 needs about ½(1 + 1/(1 − α)²) probes for an…