Merge Sort Flashcards
Which sorting algorithm uses inversions to calculate the number of swaps needed to sort a list?
merge sort
For the mechanism for merge sort, the list is _______ into two halves. Then, the ______ procedure is recursively applied to the ____ and _____ halves until each subarray contains a ______element. Finally, the two sorted subarrays are _________ back together.
divided, merge sort, left, right, single, merged
What is the worst-case time complexity for merge sort? Why?
O(n log n) because the list dividing into halves is O(log n) and merging is O(n)
What is the best-case time complexity for merge sort?
O(n log n)
What is the space complexity of merge sort? Why?
O(n) due to temporary lists created in the merge step
What prevents merge sort from performing O(n^2) despite its merge procedure?
Each element from on sorted half is only compared to the current element from the other sorted half
For space complexity, merge sort uses _______ arrays.
temporary
Does merge sort do any swaps during merging?
no!