Link
Sorting and Algorithm Bounds
Analyzing the best-possible comparison sorting algorithm, decision tree sort, and applying sort ideas in algorithm design.
Kevin Lin, with thanks to many others.
1

Optimized Binary Heap
2
Consider a heap optimization that achieves O(log* N) runtime for removing the min or max item on any input, where log* N is not in Ω(log N).
Give a runtime argument for why this optimization is impossible.
Q
Consider a heap optimization that achieves O(log* N) runtime for removing the min or max item on any input, where log* N is not in Ω(log N).

Q1: Give a runtime argument for why this optimization is impossible.

Optimized Binary Heap
3
Consider a heap optimization that achieves O(log* N) runtime for removing the min or max item on any input, where log* N is not in Ω(log N).
Give a runtime argument for why this optimization is impossible.
A

Counting Sort on Rightmost Digit
4
Q
2
3
4
8
3
4
2
8
6
4
9
5
8
7
4
4
8
4
5
7
9
3
2
5
Q1: Show the output of counting sort on the rightmost digit in the input.

Counting Sort on Rightmost Digit
5
A
2
3
4
8
3
4
2
8
6
4
9
5
8
7
4
4
8
4
5
7
9
3
2
5

Counting Sort on Rightmost + Middle Digit
6
Q
2
3
4
8
3
4
2
8
6
4
9
5
8
7
4
4
8
4
5
7
9
3
2
5
2
3
4
8
3
4
8
7
4
4
8
4
4
9
5
3
2
5
2
8
6
5
7
9
Q1: Show the output of counting sort on the rightmost + middle digit in the input, i.e. after two passes of LSD radix sort.

Counting Sort on Rightmost + Middle Digit
7
A
2
3
4
8
3
4
2
8
6
4
9
5
8
7
4
4
8
4
5
7
9
3
2
5
2
3
4
8
3
4
8
7
4
4
8
4
4
9
5
3
2
5
2
8
6
5
7
9

Left-to-Right LSD Radix Sort
8
Q
2
3
4
8
3
4
2
8
6
4
9
5
8
7
4
4
8
4
5
7
9
3
2
5
Q1: Suppose we run LSD radix sort from left to right. Does this work?

Left-to-Right LSD Radix Sort
9
A
2
3
4
8
3
4
2
8
6
4
9
5
8
7
4
4
8
4
5
7
9
3
2
5

Radix Selection Sort
Suppose we replace the counting sort used in radix sort with selection sort, resulting in two algorithms: LSD Radix Selection Sort and MSD Radix Selection Sort. Are these sorts correct?
10
Q
?: What factors are involved in the correctness of a radix sorting algorithm?



Q1: Suppose we replace the counting sort used in radix sort with selection sort, resulting in two algorithms: LSD Radix Selection Sort and MSD Radix Selection Sort. Are these sorts correct?









?: What is the time complexity of each algorithm? Space complexity?

Radix Selection Sort
Suppose we replace the counting sort used in radix sort with selection sort, resulting in two algorithms: LSD Radix Selection Sort and MSD Radix Selection Sort. Are these sorts correct?
11
A

12
Sort
Best-Case
Worst-Case
Space
Stable
Notes
Selection sort
Θ(N2)
Θ(N2)
Θ(1)
No
Heapsort
Θ(N)
Θ(N log N)
Θ(1)
No
Slow in practice.
Naive merge sort
Θ(N log N)
Θ(N log N)
Θ(N)
Yes
Java merge sort
Θ(N)
Θ(N log ρ)
Θ(N)
Yes
Fastest stable sort, ρ = number of runs.
Insertion sort
Θ(N)
Θ(N2)
Θ(1)
Yes
Best for small or almost sorted inputs.
Naive quicksort
Θ(N log N)
Θ(N2)
Θ(N)
Yes
2x or more slower than merge sort.
Java quicksort
Θ(N)
Θ(N2)
O(N)
No
Space usage depends on recursive calls.
Counting sort
Θ(N + R)
Θ(N + R)
Θ(N + R)
Yes
R = radix.
LSD radix sort
Θ(WN + WR)
Θ(WN + WR)
Θ(N + R)
Yes
W = length of longest key.
MSD radix sort
Θ(N + R)
Θ(WN + WR)
Θ(N + DR)
Yes
D = recursive depth.
On the Worst-Case Complexity of TimSort (Auger et al./Dagstuhl Research Online Publication Server)