This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1019
Â¥ = for all
Æ· = there exists
Â¥ Decision trees T for probable P on inputs of size n, Æ· a corresponding algorithm.
Â¥ Algorithms for problem P on inputs of size n, Æ· a corresponding tree
T(n)  # of possible outcomes for an input of size in
W = branching factor of modelâ€™s constant time ops My algorithm for solving problem is model takes â„¦(logwt(n)) operations
Every comparison sort is â„¦(n(log(n))
Input  An array A of integers between 0â€¦k1
COUNTINGSORT(A,n,k)
For j in 0â€¦k1
Counts(j) 0
For i in 0â€¦n1
Counts(A(i))++
i0
for j in 0â€¦k1{
for min in (1â€¦counts(j)){
A(i) j
i++
}
}
Return A
916 726 3030
314
206
713
314
206
314 206
counts 1
start 0
314 713 314
2
1 Î¸(k)
Î¸(n) Î¸(n+k) .
.
Î¸(n+k)
713
1
3 916
1
4 916 0 1 2 3 4 Counting sort can be made stable
Defn: A sort is stable if any two records w/ same key are in same relative order both before and
after sorting
Radix Sort
 Break up large numbers into d digits
 Sort one digit at a time, least significant first, using a stable sort
Original
215 421 1â€™s place
215 10â€™s place
169 100â€™s place 718
421
862
169
416 862
215
416
718
169 416
718
421
861
169 215
416
421
718
861 Claim: Radix sort correctly sorts its input
Proof: By induction on # of digits d
Base: when d = 1, #â€™s are correctly sorted by correctness of underlying per=position sort
Induction: Suppose RADIXSORT works for d1 digit inputs
Consider A(i), A(j) after sorting by 1st d digits using RADIXSORT.
o If A(i), A(j) have distinct dth digits, Then the dth pass correctly sorts then by correctness of perposition sort
o If A(i), A(j) have same dth digit, Before sorting by dth digit, these values were correctly ordered by first d1 digits by IH. Since dth digits are the same A(i), A(j) are correctly
ordered by the first d digits. The dth sort is stable, so order is preserved. Hense, A is correctly sorted up to d digits. YATAA!!!!
Running time on ddigit numbers, each written in base k isâ€¦
Î˜(d(n+k)) ...
View
Full
Document
 Spring '11
 Cytron
 Computer Science, Algorithms

Click to edit the document details