Merge Sort Flashcards

1
Q

The merge sort algorithm closely follows the divide-and-conquer paradigm.
It operates as follows.

Divide: Divide the n -element sequence to be sorted into two
subsequences of n/2 elements each.

Conquer: Sort the two subsequences recursively using merge sort.

Combine: Merge the two sorted subsequences to produce the sorted
answer.

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

How many sub-sequences will an n-element sequence be divided into?

A

2

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

How many elements are there in each sub-sequence?

A

n/2 elements (so, half the elements)

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

What sized sub-sequence is small enough to be solved in a straightforward manner?

A

1

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

The MERGE (A, p, q, r) procedure takes four parameters, what does each of them stand for?

A

A = Array
p,q,r = indices

p <= q < r

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

What is ꚙ? Why do we need it in the MERGE procedure?

A

This is the sentinel which is placed at the bottom of each subarray.
It simplifies our code by signaling that we have hit the end of the ‘pack’ and means that we don’t have to check whether or not our subarrays are empty with every iteration.

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

What is the most important operation of the merge sort algorithm?

A

The merging of two sorted sequences in the “combine” step.

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

Merge Procedure - Time

What does the merge procedure (the merge part of the algorithm) take where n = r - p + 1 (as the total number of elements being merged)?

A

theta(n)

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

Time Complexity 1

N.B log base 2 is considered cutting in half.
See YouTube https://www.youtube.com/watch?v=M4ubFru2O80
0:53 - 1:36

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