GATE Computer ScienceHardGATE CS (PYQ pattern)
Eight sorted lists of 100 keys each (800 distinct keys) are merged with the standard two-way merge, whose worst case for lists of sizes p and q is p + q - 1 comparisons. Strategy S merges list 1 with list 2, then the result with list 3, and so on up to list 8. Strategy B merges them in pairs, then the four results in pairs, then the final two. What are the worst-case total comparisons of S and of B?
- A. 3500 and 2400
- B. 3493 and 2400
- C. 2793 and 2393
- D. 3493 and 2393
Correct answer: D. 3493 and 2393
S: the k-th merge (k = 2..8) combines 100(k - 1) keys with 100, costing 100k - 1; the sum is 100(2 + ... + 8) - 7 = 3500 - 7 = 3493. B: three rounds, each touching all 800 keys: 4 merges of 200 (4 * 199), 2 of 400 (2 * 399) and 1 of 800 (799), total 2393. Forgetting the -1 per merge adds 7 to each.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- The number of nodes of a complete binary tree is found recursively: compute the leftmost-path height and the rightmost-path height of the…
- A BST is built from the sorted array 1, 2, ..., 14 by recursion: the root is a[mid] with mid = (lo + hi) / 2 (integer division), then the…
- In a binary tree given as (key, left, right) = (10, (-20, (8), (-6, (4), -)), (15, (-3), (12, (7), (-9)))), a 'path' is any sequence of…
- An AVL tree is built by inserting 1, 2, ..., 15 in increasing order (the perfect tree with root 8). Then keys 1, 3, 5, 2, 4 are deleted in…
- Cuckoo hashing uses two tables of size 7: h1(k) = k mod 7 in T1 and h2(k) = floor(k / 7) mod 7 in T2. To insert x, place it in T1[h1(x)]…
- Keys 19, 36, 5, 21, 4, 26, 14, 17, 25, 12, 40, 33 are inserted into a chained hash table with 7 buckets, h(k) = k mod 7, each new key…