Data Structures & AlgorithmsModerateIBM · Deloitte pattern
What is the auxiliary space used by the standard top-down merge sort on an array of n elements?
- A. O(log n)
- B. O(1)
- C. O(n log n)
- D. O(n)
Correct answer: D. O(n)
Merging needs a temporary array of up to n elements; the recursion stack adds only O(log n), so the total is O(n). O(log n) is the stack space of a well-implemented quick sort.
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
- In a singly linked list you are given only a pointer to a node X (not the last node) and no head pointer. How can X be deleted, and in…
- Which of these is NOT a typical application of a stack?
- A sorted array of n integers is given. Using the two-pointer technique, what are the time and extra space needed to decide whether some…
- The numbers 1, 2, 3, 4, 5 are pushed onto a stack in that order, and pops may happen at any time in between. Which output sequence is…
- Keys 15, 11, 27, 8, 12, 22, 29, 1 are inserted into a hash table of size 7 with h(k) = k mod 7 and separate chaining. What is the length…
- Keys 22, 33 and 44 are inserted in that order into an empty table of size 11 with h(k) = k mod 11 and quadratic probing hᵢ(k) = (h(k) +…