Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern
Two sorted lists of 5 and 7 elements are merged by the standard merge procedure. What is the maximum number of comparisons it can make?
- A. 12
- B. 35
- C. 11
- D. 7
Correct answer: C. 11
Every comparison outputs one element, and once one list runs out the rest is copied without comparing, so at most m + n − 1 = 11 comparisons are made (when the lists interleave to the end). The minimum is min(m, n) = 5.
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
- A fixed-size sliding window of length 3 moves over [2, 1, 5, 1, 3, 2, 9, 1]. What is the largest window sum?
- How many element shifts does insertion sort perform to sort [4, 3, 2, 10, 12, 1, 5, 6] in ascending order?
- Quick sort with the Lomuto partition (pivot = last element) is run on an already sorted array of 10 distinct elements. How many…
- Binary search (one three-way comparison per probe) is done on a sorted array of 1000 elements. What is the maximum number of probes needed?
- This code tries to reverse the singly linked list 1 → 2 → 3 → 4, but its last line has been changed from cur = nxt. What does the list…
- A linked list has 3 nodes before the loop starts and a loop of 5 nodes. Floyd's slow pointer moves 1 step and fast pointer 2 steps per…