Sorting Time Complexities Flashcards
1
Q
Quick Sort
A
- Best Case: O(nlogn)
- Average Case: O(nlogn)
- Worst Case: O(n²) (if the pivot is consistently the smallest or largest)
2
Q
Merge Sort
A
- Best Case: O(nlogn)
-Average Case: O(nlogn) - Worst: O(nlogn)
3
Q
Bubble Sort
A
- Best: O(n)
- Worst: O(n^2)
4
Q
Insertion Sort
A
- Best Case: O(n) (when the array is already sorted)
- Worst Case: O(n²) (when the array is in reverse order)
5
Q
Selection Sort
A
- Best Case: O(n²) (when the array is already sorted)
- Worst Case: O(n²) (when the array is in reverse order)
6
Q
Tree Sort
A
- Best Case: O(nlogn)
-Average Case: O(nlogn) - Worst: O(nlogn)
7
Q
Heap Sort
A
- Best Case: O(nlogn)
-Average Case: O(nlogn) - Worst: O(nlogn)
8
Q
Bucket Sort
A
- O(n) to place n items into buckets, plus O(n) to concatenate if n > d
- O(d) if n < d. Typically O(n) in practice.
d - amount of empty buckets
9
Q
Radix Sort (MSD)
A
- O((n + R) · (max. length of key))
- O(n + R) when maximum key length is constant
10
Q
Radix Sort (LSD)
A
- O((n + R) · (max. length of key)),
- O(n + R) when key length is fixed.