310 likes | 574 Views
Recurrences. Chapter 3. Growth of function Chapter 4. Recurrences. 한양대학교 정보보호 및 알고리즘 연구실 2008. 1. 11 이재준 담당교수님 : 박희진 교수님. Contents of Table. Review Asymptotic notation The substitution method The recursion-tree method The master theorem method Proof of the master theorem.
E N D
Recurrences Chapter 3. Growth of function Chapter 4. Recurrences 한양대학교 정보보호 및 알고리즘 연구실 2008. 1. 11 이재준 담당교수님 : 박희진 교수님
Contents of Table • Review • Asymptotic notation • The substitution method • The recursion-tree method • The master theorem method • Proof of the master theorem
1. Review Insertion Sort Merge Sort Asymptotic Complexity
2. Asymptotic notation • Theta[θ]-notation - [Theta] : f(n) = θ(g(n)) - for alln, n ≥ n0, If there exist positive constant c1 , c2 and n0 such that c1 g(n) ≤ f(n) ≤ c2 g(n)then, f(n) = θ(g(n)). - if g(n) is both an upper and lower bound on f(n)then, f(n) = g(n).
2. Asymptotic notation • Big Oh[O]-notation - [Big Oh] : f(n) = O(g(n)) - for alln, n ≥ n0, If there exist positive constant cand n0such that f(n) ≤ cg(n)then, f(n) = O(g(n)).
2. Asymptotic notation • Omega [Ω]-notation - [Omega] : f(n) = Ω(g(n)) - for alln, n ≥ n0, If there exist positive constant cand n0such that cg(n) ≥f(n) then, f(n) = Ω(g(n)).
Recurrences • Recurrence - Definition Equation or inequality that describes a function in terms of its value on smaller inputs. - RecurrenceSolution Method ☞ substitution method ☞ recursion-tree method ☞ master method if n=1 if n>1
Recurrences • Technicalities - Omit Technical Details ☞ assumption of integer ☞ floors ☞ ceilings ☞ boundary condition - Example (Merge Sort) if n=1 if n=1 if n>1 if n>1 Floors and ceilings Assumption of integer Boundary condition
3. The substitution method • Substitution Method - Two steps - It can be used to establish either upper or lower bounds on a recurrence. 1. Guess the form of the solution 2. Use mathematical induction to find the constant and show that the solution works.
3. The substitution method • Example • Step for substitution method 1. guess that the solution is 2. prove that ( c >0 )
3. The substitution method - Assume that this bound holds for ⌊n/2⌋, that is, T (⌊n/2⌋) ≤ c ⌊n/2⌋ lg(⌊n/2⌋). T(n) ≤ 2(c ⌊n/2⌋lg(⌊n/2⌋)) + n ≤ cnlg(n/2) + n ( because, ⌊n/2⌋ < n/2 ) = cnlgn - cnlg 2 + n = cnlgn - cn+ n ≤ cnlgn (as long as c ≥ 1)
3. The substitution method • Find the constant n0 - we can take advantage of asymptotic notation, we can replace base case T(1) ≤ cnlgn T(1) = 1 but, c1 lg1 = 0 - So, we only have to prove T (n) = cnlgn for n ≥ n0 for n (n0 =2) Replace T(1) byT(2) andT(3) as the base cases by letting n0 =2.
3. The substitution method • Find the constant c • choosing c large enough T (2) = 4 and T (3) = 5. T (2) = 4 ≤ c 2 lg 2 T (3) = 5 ≤ c 3 lg 3. Any choice of c ≥ 2 suffices for base case of n ≥ n0 , n0 =2
4. The recursion-tree method • Recursion-tree - Definition Each node represents the cost of a single subprogram somewhere in the set of recursive function invocation - The reason why we use this method ☞ A recursion-tree is best used to generate a good guess ☞ Use directly to prove the master theorem - Total Cost We sum the cost each level of the tree to obtain a set of per-level costs, and then we sum all the per-level costs to determine the total cost of all levels of the recursion
4. The recursion-tree method • Example • Draw recursion tree T (n) = 3T (⌊n/4⌋) + Θ(n2) < 3T (n/4) + cn2 cn2 cn2 T(n)
4. The recursion-tree method • Recursion-tree cn2 c(n/4)2 c(n/4)2 c(n/4)2 log4n … T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1)
4. The recursion-tree method • Total Cost - When depth ithen subprogram size is n/4i= 1so, i= log4n and it means tree’s height and tree has log4n + 1 levels. - The number of nodes at depth iis3iand finally - Total Cost is Sum of cost for idepth Sum of cost for root to i-1 depth
4. The recursion-tree method • Total Cost is..
4. The recursion-tree method • ProveT (n) = O(n2) by the substitution method - Problem - Step for substitution method T (n) = 3T (⌊n/4⌋) + Θ(n2) 1. guess that the solution is T (n) = O(n2) 2. prove that T (n) ≤ dn2(for somed > 0 and for the samec > 0)
4. The recursion-tree method • Prove.. Find constant d T(n) ≤ 3T(⌊n/4⌋) + cn2 ≤ 3d⌊n/4⌋2 + cn2 ≤ 3d(n/4)2 + cn2 = 3/16 dn2 + cn2 ≤ dn2( where the last step holds as long as d ≥ (16/13)c )
5. The master theorem method • Master theorem - Definition method for solving recurrences of the form where a≥ 1 andb > 1 are constant and f (n) is an asymptotically positive function Subprograms are solved recursively The cost of dividing the program and combining
5. The master theorem method • Master theorem if n=1 if n>1 By Assumption of integer and Boundary condition By Draw recursion tree
5. The master theorem method • Three case of master theorem The three case of master theorem correspond to cases in which the total cost of the tree. - Case 1 : dominated by the costs in the leaves. < - Case 2 : distributed across the levels of the tree. = - Case 3 : dominated by the cost of the root. >
5. The master theorem method • Master theorem • Let a≥ 1 and b > 1 are constants, let f (n) be a function, and let T (n) be defined on the nonnegative integers by the recurrence • where we interpret n/b to mean either or . Then T (n) can be bounded asymptotically as follows.1. If for some constant ε > 0, then . 2. If , then .3. If for some constant ε > 0, and if af(n/b) ≤ cf(n) for some constant c < 1 and all sufficiently large n, then .
5. The master theorem method • Exception in case of master theorem - Exception A : Gap between cases 1 and 2 when < but not polynomially smaller. - Exception B : Gap between cases 2 and 3 when > but not polynomially larger.
5. The master theorem method • Exception in case of master theorem • a=2, b=2, f (n) = n lg n, andit might be case 3? • Asymptotically larger f (n) = n lg n > (asymptotically larger) • But not Polynomially larger The ratio is asymptotically less than for any positive constant k(polynomially smaller) • Recurrence falls into gap between cases 2 and 3.
6. The proof of master theorem • Case 1 : dominated by the costs in the leaves. we have for some constant ,then so, ,which implies that ..
6. The proof of master theorem • Case 1 : dominated by the costs in the leaves. Constant value
6. The proof of master theorem • Case 2 : distributed across the levels of the tree.
6. The proof of master theorem • Case 3 : dominated by the cost of the root. We assume thataf(n/b) ≤ cf(n) for some constant and c < 1, all n ≥ b, ( Iterating jtimes )
Thank you Q & A