10-19 notes - 10-19 ¥ = for all Ʒ = there exists ¥...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 10-19 ¥ = 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…k-1 COUNTINGSORT(A,n,k) For j in 0…k-1 Counts(j) 0 For i in 0…n-1 Counts(A(i))++ i0 for j in 0…k-1{ 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 d-1 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 per-position 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 d-digit numbers, each written in base k is… Θ(d(n+k)) ...
View Full Document

Page1 / 2

10-19 notes - 10-19 ¥ = for all Ʒ = there exists ¥...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online