Data Structures & AlgorithmsHardTCS NQT · Infosys pattern
How many comparisons does top-down merge sort (split in halves, stop comparing when one side runs out) make on [5, 1, 7, 3, 20, 15, 30, 25]?
- A. 24
- B. 17
- C. 13
- D. 16
Correct answer: C. 13
Four pair merges take 1 each (4). [1,5] with [3,7] takes 3; [15,20] with [25,30] takes 2 (the left side runs out). The final merge of [1,3,5,7] with [15,20,25,30] takes only 4, so 4 + 5 + 4 = 13. 17 is the worst case for 8 elements, not this input.
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
- 1800 keys are stored in a hash table with 600 slots using separate chaining and simple uniform hashing. About how many key comparisons…
- How many distinct non-empty substrings does the string ABAB have?
- What is the KMP failure (LPS) array for the pattern AABAACAABAA?
- The reversal algorithm rotates an array LEFT by k: reverse the first k elements, reverse the rest, then reverse the whole array. What is…
- Which statement about a doubly linked list compared with a singly linked list is FALSE?
- How many of these statements are correct? (i) Merge sort is stable. (ii) Heap sort runs in O(n log n) even in the worst case. (iii) Quick…