Data Structures & AlgorithmsHardProduct-company MCQ pattern
What is the maximum number of comparisons top-down merge sort can make on 8 elements (any input order)?
- A. 16
- B. 28
- C. 17
- D. 24
Correct answer: C. 17
In the worst case each merge of sizes m and n takes m + n − 1: 4 × 1 + 2 × 3 + 1 × 7 = 17 = n log₂ n − n + 1 = 24 − 8 + 1. 24 is the rough n log₂ n estimate, and checking all 8! inputs confirms 17.
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
- What is the minimum number of comparisons needed, in the worst case, to find BOTH the maximum and the minimum of 100 distinct numbers?
- One Lomuto partition (pivot = last element, i marks the end of the 'smaller' part, swap when a[j] < pivot) is applied to [7, 2, 9, 4, 3…
- Insertion sort (ascending) is applied to [5, 2, 4, 6, 1, 3]. What does the array look like after the first 3 passes (i.e. after inserting…
- Among insertion sort, merge sort, heap sort, quick sort, bubble sort and selection sort (standard array versions), how many are BOTH…
- LSD radix sort (base 10, stable counting sort per digit) is applied to [170, 45, 75, 90, 802, 24, 2, 66]. What is the array after the…
- What does this function return for a = [1, 3, 3, 3, 5, 7] with x = 3 and with x = 4? python def g(a, x): lo, hi = 0, len(a) - 1 while lo <…