Sorting Algorithms Flashcards
What are the Non-Recursive/Incremental Comparison Sorting Algorithms?
- Selection Sort
- Bubble Sort
- Insertion Sort
What are the Best, Worst, and Average Case of Selection Sort Algorithm?
Best: O(n^2)
Worst: O(n^2)
Average: O(n^2)
What are the Best, Worst, and Average Case of Bubble Sort Algorithm?
Best: O(n^2)
Worst: O(n^2)
Average: O(n^2)
What are the Best, Worst, and Average Case of Modified Bubble Sort Algorithm?
Best: O(n)
Worst: O(n^2)
Average: O(n^2)
What are the Best, Worst, and Average Case of Insertion Sort Algorithm?
Best: O(n^2)
Worst: O(n^2)
Average: O(n^2)
What are the Recursive Comparison Sorting Algorithms?
- Merge Sort
- Quick Sort
- Heap Sort
What are the Best, Worst, and Average Case of Merge Sort Algorithm?
Best: O(nlogn)
Worst: O(nlogn)
Average: O(nlogn)
What are the Best, Worst, and Average Case of Quick Sort Algorithm?
Best: O(nlogn)
Worst: O(n^2)
Average: O(nlogn)
What are the Best, Worst, and Average Case of Heap Sort Algorithm?
Best: O(nlogn)
Worst: O(nlogn)
Average: O(nlogn)
When should you use Strategy 1 (Pick the First Element in S) when picking a pivot?
If input is random and not sorted
When should you use Strategy 2 (Pick the Pivot Randomly) when picking a pivot?
Random Number Generation is an expensive operation
How do you find the pivot in Strategy w (Median-of-Three Partitioning)?
Median of the left-most, right-most, and center elements of array S
What happens to Quick Sort when the array contains multiple duplicate elements?
Unstable
What is the theorem for lower-bound comparison sorting?
To sort n elements, comparison sorts must make Ω(nlgn) comparisons in the worst case.