[PDF] Master Theorem: Practice Problems and Solutions





Previous PDF Next PDF



CS 161 Lecture 3 - 1 Solving recurrences

Last class we introduced recurrence relations such as T(n) = 2T(?n/2?) + n. Typically Here a = 9



Discrete Mathematics II (Spring 2015) - 8.2 Solving Linear

Determine what is the degree of the recurrence relation. • Need to know the general solution equations. • Need to find characteristic equation. • Need to find 



Recurrences

n = 2k for some constant k and leaving out base case and constant in ?). Methods for solving recurrences. 1. Substitution method. 2. Iteration method.



Q1: Exercise 2.3-3 (10 points) Use mathematical induction to show

recurrence. T(n) =2 ifn=2. 2T(n/2) + n if n = 2k for k > 1 is T(n) = n logn. . Base Step: If n = 2



Master Theorem: Practice Problems and Solutions

The Master Theorem applies to recurrences of the following form: 2. T(n)=4T(n/2) + n2. 3. T(n) = T(n/2) + 2n. 4. T(n)=2nT(n/2) + nn.



GENERATING FUNCTIONS AND RECURRENCE RELATIONS

A recurrence recurrence relation is a set of equations Linear Recurrence. Fibonacci Sequence an = an?1 + an?2 n ? 2. ... n=2 n(n ? 1)xn +.



Solving Recurrences

For example the following recurrence (written in two different but standard ways) describes the identity function f (n) = n:.



1.1 Time complexity and Big-Oh notation: exercises

2. A quadratic algorithm with processing time T(n) = cn2 spends T(N) To have the well-defined recurrence assume that n = km with the integer.



Sample Induction Proofs

(?1)nn(n + 1). 2 . Base case: When n = 1 the left side of (1) is (?1)12 = ?1



3. Recurrence 3.1. Recursive Definitions. To construct a recursively

Example 3.2.1. The factorial function f(n) = n! is defined recursively as follows: 1. Initial Condition: f(0) = 1. 2. Recursion: f(n +1)=(n + 1)f(n).



Recurrence Relations - Hong Kong University of Science and

an= 2 n¡1; n ‚1: Given a recurrence relation for a sequence with initial conditions Solving the recurrence relation means to ?nd a formula to express the general termanof the sequence 2 Homogeneous Recurrence Relations Any recurrence relation of the form



Solving Recurrence Relations - Texas A&M University

n 2 and the base cases of the induction proof (which is not the same as the base case of the recurrence!) are n= 2 and n= 3 (We are allowed to do this because asymptotic notation only requires us to prove our statement for n n 0 and we can set n 0 = 2 ) We choose n= 2 and n= 3 for our base cases because when we expand the recurrence



Recurrence Relations - University of Ottawa

Many sequences can be a solution for the same recurrence relation a n = 2a n 1 a n 2; for n 2 The following sequences are solutions of this recurrence relation: I a n = 3n for all n 0 I a n = 5 for all n 0 The initial conditions for a sequence specify the terms before n 0 (before the recurrence relation takes e ect)



Solving Recurrence Relations - Princeton University

n 2 to be C0 and C1 Since the sequences fang and f 1rn 1 + 2r n 2g satisfy the degree 2 recurrence and agree on the rst two values they must be identical Example: Find the solution to the recurrence relation an = an 1 +an 2 with initial condi-tions a0 = 2 and a1 = 7 Solution: The characteristic equation is r2 r 2 = 0 i e (r 2)(r +1) = 0



Recurrence Relations - University of Illinois Urbana-Champaign

2 Recall that 1=nk= nk and we have rn 2(r25r + 6) = 0 Then we can factor the polynomial into rn 2(r 2)(r 3) = 0 We assumed that r is non-zero so we can divide by the rst factor rn 2 which leaves (r 2)(r 3) = 0 Thus the characteristic function (also: polynomial) remains on the left-hand side



Searches related to 2^n n^2 recurrence PDF

n = 2n for every nonnegative integer n is a solution of the recurrence relation a n = 2a n-1 - a n-2 for n = 234 Assume a 0=1 and a 1=2 Solution: Check initial conditions a 0= 20 = 1 a 1= 2 1 = 2 Check if {2n} satisfies a n = 2a n-1 - a n-2 2a n-1 - a n-2 = 2(2n-1) - 2n-2 = 2n-2(4-1) = 3(2n-2) 2n So {2n} is not a solution for a n = 2a

What is the solution of the recurrence relation?

.Thenasequence (a n ) is a solution of the recurrence relation a n= c 1a n?1+ c 2a n?2 if and only if a n= ? 1r n 1+ ? 2r n 2 for n ? 0 for some constants ? 1,? 2 Idea of the Proof The proof proceeds exactly as in the case of the Fibonacci numbers. Try to prove it yourself!

What is the solution of recurrence relation an = 10an-1 - 25an-2?

The solution of the recurrence relation an = 10an-1 - 25an-2, is: (a0 = 1, a1 = 15) Q8. Solution to recurrence relation T (n) = T (n - 1) + 4 is given by, where n > 0 and T (0) = 3.

What is a 2 nd-order linear recurrence?

This is a subset of the type of 2 nd -order recurrence formulas used by MCS . The Fibonacci number s are the best-known example of a 2 nd -order linear recurrence.

What is the initial condition for a recurrence relation?

So (a_n = 3a_ {n-1} + 2) is our recurrence relation and the initial condition is (a_0 = 1 ext {.}) We are going to try to solve these recurrence relations.

Master Theorem:

Practice Problems and Solutions

Master Theorem

The Master Theorem applies to recurrences of the following form:

T(n) =aT(n/b) +f(n)

wherea≥1 andb >1 are constants andf(n) is an asymptotically positive function.

There are 3 cases:

1. Iff(n) =O(nlogba-?) for some constant? >0, thenT(n) = Θ(nlogba).

2. Iff(n) = Θ(nlogbalogkn) with1k≥0, thenT(n) = Θ(nlogbalogk+1n).

3. Iff(n) = Ω(nlogba+?) with? >0, andf(n) satisfies the regularity condition, thenT(n) = Θ(f(n)).

Practice Problems

For each of the following recurrences, give an expression for the runtimeT(n) if the recurrence can be

solved with the Master Theorem. Otherwise, indicate that the Master Theorem does not apply.

1.T(n) = 3T(n/2)+n2

2.T(n) = 4T(n/2)+n2

3.T(n) =T(n/2) + 2n

4.T(n) = 2nT(n/2) +nn

5.T(n) = 16T(n/4)+n

6.T(n) = 2T(n/2)+nlogn

1most of the time,k= 0

1

7.T(n) = 2T(n/2)+n/logn

8.T(n) = 2T(n/4)+n0.51

9.T(n) = 0.5T(n/2)+ 1/n

10.T(n) = 16T(n/4)+n!

11.T(n) =⎷

2T(n/2) + logn

12.T(n) = 3T(n/2)+n

13.T(n) = 3T(n/3)+⎷

n

14.T(n) = 4T(n/2)+cn

15.T(n) = 3T(n/4)+nlogn

16.T(n) = 3T(n/3)+n/2

17.T(n) = 6T(n/3)+n2logn

18.T(n) = 4T(n/2)+n/logn

19.T(n) = 64T(n/8)-n2logn

20.T(n) = 7T(n/3)+n2

21.T(n) = 4T(n/2)+ logn

22.T(n) =T(n/2) +n(2-cosn)

2

Solutions

1.T(n) = 3T(n/2)+n2=?T(n) = Θ(n2) (Case 3)

2.T(n) = 4T(n/2)+n2=?T(n) = Θ(n2logn) (Case 2)

3.T(n) =T(n/2) + 2n=?Θ(2n) (Case 3)

4.T(n) = 2nT(n/2) +nn=?Does not apply (ais not constant)

5.T(n) = 16T(n/4)+n=?T(n) = Θ(n2) (Case 1)

6.T(n) = 2T(n/2)+nlogn=?T(n) =nlog2n(Case 2)

7.T(n) = 2T(n/2)+n/logn=?Does not apply (non-polynomial difference betweenf(n) andnlogba)

8.T(n) = 2T(n/4)+n0.51=?T(n) = Θ(n0.51) (Case 3)

9.T(n) = 0.5T(n/2)+ 1/n=?Does not apply (a <1)

10.T(n) = 16T(n/4)+n! =?T(n) = Θ(n!) (Case 3)

11.T(n) =⎷

2T(n/2) + logn=?T(n) = Θ(⎷n) (Case 1)

12.T(n) = 3T(n/2)+n=?T(n) = Θ(nlg3) (Case 1)

13.T(n) = 3T(n/3)+⎷

n=?T(n) = Θ(n) (Case 1)

14.T(n) = 4T(n/2)+cn=?T(n) = Θ(n2) (Case 1)

15.T(n) = 3T(n/4)+nlogn=?T(n) = Θ(nlogn) (Case 3)

16.T(n) = 3T(n/3)+n/2 =?T(n) = Θ(nlogn) (Case 2)

17.T(n) = 6T(n/3)+n2logn=?T(n) = Θ(n2logn) (Case 3)

18.T(n) = 4T(n/2)+n/logn=?T(n) = Θ(n2) (Case 1)

19.T(n) = 64T(n/8)-n2logn=?Does not apply (f(n) is not positive)

20.T(n) = 7T(n/3)+n2=?T(n) = Θ(n2) (Case 3)

21.T(n) = 4T(n/2)+ logn=?T(n) = Θ(n2) (Case 1)

22.T(n) =T(n/2) +n(2-cosn) =?Does not apply. We are in Case 3, but the regularity conditionis

violated. (Considern= 2πk, wherekis odd and arbitrarily large. For any such choice ofn, you can show thatc≥3/2, thereby violating the regularity condition.) 3quotesdbs_dbs22.pdfusesText_28
[PDF] la composante vivante dun milieu naturel

[PDF] les composantes de lenvironnement 6ème

[PDF] quelles sont les composantes de lenvironnement

[PDF] les composantes de l'environnement svt 6ème

[PDF] les composantes dun milieu naturel

[PDF] quelles sont les composantes dun milieu naturel

[PDF] les elements qui composent l'environnement

[PDF] les composantes de lenvironnement pdf

[PDF] 1.1.1 tenue des dossiers fournisseurs et sous-traitants

[PDF] 1.1.4 evaluation et suivi des stocks

[PDF] 1.2.3 traitement des devis des commandes

[PDF] 1.2.4 traitement des livraisons et de la facturation

[PDF] 1.3.1 suivi de la trésorerie et des relations avec les banques

[PDF] tenue des dossiers clients donneurs d ordre et usagers

[PDF] 2.2.3 suivi administratif des carrières