Comparison model
- all input items are black boxes (ADTS)
- only operations allowed are comparisons (<,<=,>,>=)
- time cost = # comparisons
Decision tree
any comparison algorithm can be viewed as a tree of all possible comps & outcomes
- internal node = binary decision
- leaf = output
- root-to-leaf path = algorithm execution
- path length = running time
- the height of tree = worst-case running time
Lower bound
Claim:
- n preprocessed items
- finding a given item among them in comparison model requires in worst-case
- sorting n items requires
Linear time sorting(Integer sorting)
- assume n keys sorting are integers ∈ {0, 1, 2, 3, ... , k-1} (&each fits in a word)
- can do a lot more than comparisons
- can sort in O(n) time
Counting Sort
L = array of k empty lists lists
for j in range n:
L[key(A[j])].append(A[j])
output = []
for i in range k:
output.extend(L[i])
Radix Sort
- imagine each integer in base b
- sort by least significant digit
- ...
- sort by most signigicant digit
- use counting sort for digit sort
minimized when b = n