2.1 Merge Sort Flashcards

1
Q

What is Divide and Conquer?

A

Divide: an instance into smaller instances of the same problem
Conquer: by recursively solving the sub-instances until we can solve directly
Combine: the partial solutions to the solution for the original instance

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

What is recursion

A

A function that calls itself

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

When combining left and right part of array, what are the formulas for n1 and n2? (the lengths of the two arrays)

A

n1 = m - L + 1
n2 = r - m

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

What is a sentinel

A

Usually infinity, used to compare to the biggest number in the array. So the biggest number in the array is compared and then goes at the end.

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

How many comparisons does Merge make?

A

r - L + 1 (n)

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

What techniques are used to prove correctness of MergeSort?

A

Using proof by induction

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

Can merge sort be done in situ (using only the array you were given and no extra space)

A

No

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

Is MergeSort stable? If there are 2 1’s in the array will the first 1 always stay before the second 1?

A

Yes

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

Pros and Cons of merge sort

A

Pro:
Divide and Conquer
Good ‘worst case’ running time O(nlog(n))

Con:
Not in situ (needs an extra n space)

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