Sorting Algorithms Flashcards

1
Q

What is the order of runtime from fastest to slowest?

A

1, log(n), n, nlog(n), n^2, 2^n, n!

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

What is the runtime (worst case and best case) of bubble sort?

A

Worst case: n^2, array is reversed
Best case: n, if data is sorted and the algorithm is optimized. Meaning there is a way to exit early.

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

What is the runtime (worst case and best case) of insertion sort?

A

Worst case: n^2, if array is reversed
Best case: n, if array is sorted

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

What is the runtime (worst case and best case) of selection sort?

A

n^2 for best and worst case. No mechanism to know when it’s done working so it looks through the whole list again and again

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

What are the non-comparison sorting algorithms? What is their runtime?

A

Counting sort
Radix sort
Both run in linear, n, time.

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

What are the divide and conquer algorithms?

A

Merge sort
Quick sort

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

What is the runtime (worst case and best case) of merge sort?

A

It is always nlog(n). The best case and worst case are nlog(n). No mechanism to figure out if it’s done working, so it will just keep splitting and working on the list. Needs extra space.

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

What is the runtime (worst case and best case) of quick sort?

A

Worst case: n^2
Best case: nlog(n)
The runtime is based on the position of the pivot used. Pivot should be somewhere in/near the middle to get the best case runtime.

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

What does merge sort need that quick sort does not need?

A

Merge sort needs needs extra space. So an extra array needs to be created.

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