- Sorting In Linear Time
Ting-Yun Tseng
曾庭筠
2014/09/27
- only use comparisons to determine relative order of elements.
view comparison sorts abstractly in terms of decision trees
Control, data movement, and all other aspects of the algorithm are ignored
A = {a1, a2, a3, a4}
Draw the Decision Tree for Merge Sort on A
Use decision tree to clarify the meaning of Running Time
According to the former theorem...
[Corollary]
Input : A[1,2,...n], each A[i] belongs to {1,2,...,k}
Output : B[1,2,....n] = sorting of A
Running Time of Counting Sort = theta(k+n)
**Counting Sort is a stable sorting algorithm
Stable Sorting Algorithm preserves the relative order of equal elements
[***Explanation on white board***]
Answer : Insertion Sort and Merge Sort are stable.
QuickSort is not stable.
Input : A[1,2,...,n], each A[i] has d digits where digit 1 is the lowest-order digit and digit d is the highest-order digit.
Output : A[1',2',...,n'] with A[1']<=...<=A[n']
Decimal digits (Lemma8.3)
Binary digits (Lemma8.4)
Given n b-bits numbers, and any positive number r>0