Data Structures & AlgorithmsVery hardGATE CS · Product placement
Top-down merge sort (split at mid = n // 2, recurse, then merge, stopping comparisons when one side runs out) sorts [33, 53, 13, 42, 11, 36, 5]. How many key comparisons does it make?
- A. 20
- B. 21
- C. 12
- D. 14
Correct answer: D. 14
Merges: [53|13] 1, [33|13,53] 2, [42|11] 1, [36|5] 1, [11,42|5,36] 3, [13,33,53|5,11,36,42] 6: total 14. Counting the leftover copies as comparisons gives 20, splitting at ⌈n/2⌉ gives 12, and 21 is the loose n⌈log₂ n⌉ bound.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Assertion (A): Removing duplicates from a sorted array can be done in place in O(n) time with two pointers. Reason (R): In a sorted array…
- Assertion (A): Quick sort with the last element as pivot takes Θ(n²) time on an array that is already sorted. Reason (R): On sorted input…
- A Python 2-D list is created two ways and one cell is set. What is printed? python a = [[0] 3] 3 b = [[0] 3 for in range(3)] a[2][2] = 5…
- Rearrange a linked list so that nodes at odd POSITIONS (1st, 3rd, …) come first, followed by the even-position nodes, keeping relative…
- What is the length of the longest contiguous substring of ((()((()(()) that is a valid (balanced) parentheses string?
- Reverse a singly linked list in groups of k (a final group shorter than k is left as it is). What is printed? python def revk(h, k): cnt…