Sorting Algorithms Flashcards
What are the three basic sorting algorithms?
- Bubble Sort
- Selection Sort
- Insertion Sort
What are the six advanced sorting algorithms?
- Merge Sort
- Heap Sort
- Quick Sort
- Counting Sort
- Bucket Sort
- Radix sort
What is the runtime and stability of bubble sort?
Tbest: Theta(n)
Tworst: Theta (n^2)
Taverege: Theta (n^2)
Toverall: O(n^2)
Stability: Yes
What is the runtime and stability of selection sort?
Tbest: Theta(n^2)
Tworst: Theta(n^2)
Taverege: Theta(n^2)
Toverall: Theta(n^2)
Stable: No
What is the runtime and stability of insertion sort?
Tbest: Theta(n)
Tworst: Theta(n^2)
Taverege: Theta(n^2)
Toverall: O(n^2)
Stable: Yes
Why is selection sort faster than bubble sort if their runtimes are the same?
Selection sort makes far fewer comparisons. This is selection sort makes exactly N(N-1)/2 comparisons
What is the runtime, space, and stability of Merge Sort?
Runtime: Theta (N lgN)
Space: Theta (N)
Stable: Yes
What is the runtime and stability of Heap Sort?
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
What is the runtime and stability of Quick Sort , and what is challenging about implementing it?
Tbest: Theta (N lgN)
Tworst: Theta (n^2)
Stable: No
The most challenging aspect of heapsort is picking a pivot element.
What is the runtime and stability of Counting Sort ?
Toverall: Theta (N+M)
Stable: Yes
What are the runtime, space complexity, and stability of Bucket Sort?
Toverall: Theta (N+M)
Space: Theta (N+M)
Stable: Yes
What is the runtime, space complexity, and stability of Radix Sort?
Tbest:
Tworst:
Taverege:
Toverall:
Stable:
How does partitioning in place work (quick sort)?
Use swaps to push all elements x >= v to the right.
What algorithm was introduced in class to partition quicksort arrays?
Lomuto Partition
What is the most evident limitation of counting sort?
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.