Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Standard top-down merge sort is run on [3, 48, 14, 99, 61, 71, 8, 15]. How many element comparisons happen during all the merge steps combined?
- A. 16
- B. 18
- C. 17
- D. 15
Correct answer: A. 16
Recursively split in half, then merge: each merge step compares the fronts of the two halves until one is exhausted. Total comparisons across all merges: 16.
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
- Quicksort with Lomuto partitioning (last element as pivot) sorts [84, 38, 96, 7, 19, 64, 7, 94]. How many swaps happen in total, across…
- A singly linked list has nodes at positions 0..4 holding 19 -> 83 -> 57 -> 22 -> 13, but the last node's next pointer points back to the…
- A singly linked list holds 50 -> 31 -> 76 -> 53 -> 96 -> None (in that order, 5 nodes). Using the standard two-pointer technique (advance…
- Quicksort with Lomuto partitioning (last element as pivot) sorts [52, 89, 77, 41, 89, 97, 29, 94]. How many swaps happen in total, across…
- A singly linked list has nodes at positions 0..5 holding 38 -> 23 -> 89 -> 67 -> 63 -> 79, but the last node's next pointer points back to…
- Two nested loops iterate: the outer runs n times, and for each outer iteration the inner loop runs from 1 up to the current outer index i…