10.07.2015 Views

Divide and Conquer

Divide and Conquer

Divide and Conquer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Divide</strong> <strong>and</strong> <strong>Conquer</strong> 2– Run-time determined by the size <strong>and</strong> number of subproblems to be solved in addition to the time required fordecomposition– General complexity computationT n =where a <strong>and</strong> b are known constants; assume that n = b k• Example, mergesort recurrenceSolution for the mergesort recurrence: Θ(n lg n){T1 n = 1aT n/b + f(n) n > 1{ Θ(1) if n = 1T n =2T n + Θ(n) if n > 12• You can ignore extreme details like floor, ceiling, <strong>and</strong> boundary in recurrence description.• Solving recurrence relations by substitution method– Guess the form of solution <strong>and</strong> use mathematical induction to find constants– Determine upper bound on the recurrenceGuess the solution as: T n = O(n lg n)Now, prove that T n ≤ cn lg n for some c > 0Assume that the bound holds for ⌊ ⌋n2Substituting into the recurrenceT n = 2T ⌊ n2 ⌋ + n⌊ n⌋T n ≤ 2(c2Boundary condition: Let the only bound be T 1 = 1≤cn lg⌊ n⌋lg(2( n2)+ n)) + n= cn lg n − cn lg 2 + n= cn lg n − cn + n≤ cn lg n ∀c ≥ 1̸ ∃c | T 1 ≤ c1 lg 1 = 0Problem overcome by the fact that asymptotic notation requires us to proveInclude T 2 <strong>and</strong> T 3 as boundary conditions for the proofChoose c such that T 2 ≤ c2 lg 2 <strong>and</strong> T 3 ≤ c3 lg 3True for any c ≥ 2– Making a good guessT n ≤ cn lg n for n ≥ n 0T 2 = 4 T 3 = 5∗ If a recurrence is similar to a known recurrence, it is reasonable to guess a similar solutionT n = 2T ⌊ n2 ⌋ + nIf n is large, difference between T ⌊ n2 ⌋ <strong>and</strong> T ⌊ n2 ⌋+17 is relatively small∗ Prove upper <strong>and</strong> lower bounds on a recurrence <strong>and</strong> reduce the range of uncertaintyStart with a lower bound of T n = Ω(n) <strong>and</strong> an initial upper bound of T n = O(n 2 ). Gradually lower the upperbound <strong>and</strong> raise the lower bound to get asymptotically tight solution of T n = Θ(n lg n)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!