Sorting Algorithms Flashcards

1
Q

What are the three basic sorting algorithms?

A
  1. Bubble Sort
  2. Selection Sort
  3. Insertion Sort
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the six advanced sorting algorithms?

A
  1. Merge Sort
  2. Heap Sort
  3. Quick Sort
  4. Counting Sort
  5. Bucket Sort
  6. Radix sort
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the runtime and stability of bubble sort?

A

Tbest: Theta(n)
Tworst: Theta (n^2)
Taverege: Theta (n^2)
Toverall: O(n^2)

Stability: Yes

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

What is the runtime and stability of selection sort?

A

Tbest: Theta(n^2)
Tworst: Theta(n^2)
Taverege: Theta(n^2)
Toverall: Theta(n^2)

Stable: No

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

What is the runtime and stability of insertion sort?

A

Tbest: Theta(n)
Tworst: Theta(n^2)
Taverege: Theta(n^2)
Toverall: O(n^2)

Stable: Yes

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

Why is selection sort faster than bubble sort if their runtimes are the same?

A

Selection sort makes far fewer comparisons. This is selection sort makes exactly N(N-1)/2 comparisons

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

What is the runtime, space, and stability of Merge Sort?

A

Runtime: Theta (N lgN)
Space: Theta (N)
Stable: Yes

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

What is the runtime and stability of Heap Sort?

A

Runtime: Theta(N lgN)
Build Heap –> Theta(N)
Perform N deleteMin operations to retrieve the elements in sorted order –> O(lgN)

Space: O(N)
Stable: No

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

What is the runtime and stability of Quick Sort , and what is challenging about implementing it?

A

Tbest: Theta (N lgN)
Tworst: Theta (n^2)

Stable: No

The most challenging aspect of heapsort is picking a pivot element.

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

What is the runtime and stability of Counting Sort ?

A

Toverall: Theta (N+M)

Stable: Yes

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

What are the runtime, space complexity, and stability of Bucket Sort?

A

Toverall: Theta (N+M)
Space: Theta (N+M)
Stable: Yes

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

What is the runtime, space complexity, and stability of Radix Sort?

A

Tbest:
Tworst:
Taverege:
Toverall:

Stable:

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

How does partitioning in place work (quick sort)?

A

Use swaps to push all elements x >= v to the right.

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

What algorithm was introduced in class to partition quicksort arrays?

A

Lomuto Partition

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

What is the most evident limitation of counting sort?

A

You need to use an array that with an index count large enough to match every value. This becomes impossible if you are storing large values.

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