2.2 Runtime Analysis Flashcards

1
Q

What is running time complexity of Insertion sort (best and worst cases)?

A

Best: n - 1
Worst: (n^2 - n) / 2

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

How do you calculate the runtime complexity of mergeSort

A

n * height of the tree

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

How do you calculate the height of the tree in MergeSort

A

Log(2)N

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

What is the runtime complexity of MergeSort

A

N * Log(2)N

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

Draw the symbols for a quadratic function for:
grows at most
grows at least
grows exactly
grows slower than
grows faster than

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

Order these by asymptotic growth:
n^3
1
sqrt(n)
nlogn
n
n^2
2^n
logn

A

1
logn
sqrt(n)
n
nlogn
n^2
n^3
2^n

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

Worst case, average and best case runtime complexity for insertion sort

A

Worst: O(n^2)
Average: O(n^2)
Best: O(n)

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

Worst case, average and best case runtime complexity for MergeSort sort

A

O(nlogn)

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

Worst case, average and best case runtime complexity for HeapSort sort

A

O(nlogn)

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

Is InsertionSort 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
11
Q

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

A

Yes

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