Medium · O(n log n)
Merge Sort quiz
Answer the questions in your own time, change a pick whenever you like, then hand in to see your score and why each answer is right. Nothing is saved or sent.
Questions (10)
- Viewing
- Answered
- Not answered
mergeSort runs on [38, 27, 43, 3, 9, 82, 10], seven values. The code sets mid = lo + Math.floor((hi - lo) / 2). Which two halves does the first split make?
Same array, [38, 27, 43, 3, 9, 82, 10]. The recursion sorts the left half completely before it touches the right one. Which merge runs first?
The last merge joins the sorted halves [27, 38, 43] and [3, 9, 10, 82]. How many times does it compare two values?
A tester sorts records by key. They start as 3a, 1x, 3b, 2y, 3c, 1z (the letter is the order of arrival). Someone changes <= to < in the merge. What comes out?
How much extra memory does this listing use to sort n values?
What does const sorted = mergeSort(values) leave you with?
The listing sorts eight values. How many comparisons does it make on the sorted [1, 2, 3, 4, 5, 6, 7, 8], and on the interleaved [1, 3, 5, 7, 2, 4, 6, 8]?
For 1000 values, how many sortRange calls are on the call stack at the deepest point, counting the very first one?
During a sort of [1, 2, 3, 4, 5] the top-level merge joins [1, 2] and [3, 4, 5]. How many times does it write into values? (Copying into buffer doesn't count.)
Counting inversions (pairs i < j with a[i] > a[j]) by merge sort: each time a merge takes a value from the right half, add mid - i. What total does this give for [8, 3, 5, 3, 9, 1]?
Progress
0 / 10 questions0%
10 questions left
Quiz details
- Total questions
- 10
- Answered
- 0
- Not answered
- 10