GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Two sorted lists of 8 keys each are merged by the standard merge, which stops comparing when one list runs out. All C(16, 8) = 12870 interleavings of the two lists are possible. For how many of them does the merge make exactly 15 comparisons?
- A. 6864
- B. 12870
- C. 3432
- D. 6435
Correct answer: A. 6864
The merge makes 16 − r comparisons, where r is the length of the final run of keys from the same list. 15 comparisons means r = 1: the last two keys come from different lists. Fixing the last two (AB or BA) leaves C(14, 7) = 3432 arrangements each, so 2·3432 = 6864.
More Algorithms questions
- What is the length of the longest common subsequence of the three strings X = BDCABACDB, Y = ABCBDABDC and Z = BCADBDACB?
- The longest repeating subsequence of a string is the longest subsequence that occurs twice, where the two copies may overlap in positions…
- Characters may be added ONLY at the front of the string abacdcabxab. What is the minimum number of characters that must be added to make…
- A digit string is decoded using A = 1, B = 2, …, Z = 26, and each code must be a valid letter number (so 0 is allowed only as part of 10…
- What is the maximum product of a non-empty contiguous subarray of [−2, 3, −4, 0, 5, −1, 2, −3, −1, 4]?
- The numbers 19, 5, 9, 18, 10, 29, 5, 24, 10 are split into two groups (every number goes into exactly one group). What is the smallest…