Data Structures & AlgorithmsModerateGATE CS · Product placement
Merge sort and quick sort are compared. Which statement is correct?
- A. Merge sort is in place for arrays and quick sort needs Θ(n) extra space
- B. Quick sort is stable and merge sort is not
- C. Both have O(n²) worst cases
- D. Merge sort guarantees O(n log n) but needs Θ(n) extra space for arrays; quick sort is in place (O(log n) stack expected) but has an O(n²) worst case
Correct answer: D. Merge sort guarantees O(n log n) but needs Θ(n) extra space for arrays; quick sort is in place (O(log n) stack expected) but has an O(n²) worst case
Array merge sort needs an auxiliary buffer; quick sort partitions in place but degrades to Θ(n²) with bad pivots. Neither standard quick sort nor heap sort is stable.
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
- Bars of width 1 have heights [7, 3, 3, 6, 1, 3, 7, 1, 1]. How many units of rain water are trapped between them (two-pointer method with…
- Bubble sort (ascending; each pass compares adjacent pairs left to right and swaps if out of order) is applied to [49, 52, 21, 37, 35, 19…
- Z-array: z[i] is the length of the longest common prefix of s and s[i:], with z[0] defined as 0. What is printed? python s = "aaaaabaaa" z…
- 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[0][1] = 5…
- An array of size 9 holds the numbers 1..9, except that one number is missing and one number appears twice: [6, 5, 1, 3, 4, 7, 2, 8, 2]…
- Overlapping versus non-overlapping substring counts. What is printed? python s, p = "aababaaabbba", "aba" over = sum(1 for i in…