Merge Sort Flashcards

1
Q

Which sorting algorithm uses inversions to calculate the number of swaps needed to sort a list?

A

merge sort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

divided, merge sort, left, right, single, merged

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the worst-case time complexity for merge sort? Why?

A

O(n log n) because the list dividing into halves is O(log n) and merging is O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the best-case time complexity for merge sort?

A

O(n log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the space complexity of merge sort? Why?

A

O(n) due to temporary lists created in the merge step

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What prevents merge sort from performing O(n^2) despite its merge procedure?

A

Each element from on sorted half is only compared to the current element from the other sorted half

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

For space complexity, merge sort uses _______ arrays.

A

temporary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Does merge sort do any swaps during merging?

A

no!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly