SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
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)

   where a ≥ 1 and b > 1 are constants and f (n) is an asymptotically positive function.
   There are 3 cases:

  1. If f (n) = O(nlogb a− ) for some constant   > 0, then T (n) = Θ(nlogb a ).
  2. If f (n) = Θ(nlogb a logk n) with1 k ≥ 0, then T (n) = Θ(nlogb a logk+1 n).
  3. If f (n) = Ω(nlogb a+ ) with > 0, and f (n) satisfies the regularity condition, then T (n) = Θ(f (n)).
     Regularity condition: af (n/b) ≤ cf (n) for some constant c < 1 and all sufficiently large n.

Practice Problems
    For each of the following recurrences, give an expression for the runtime T (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) = 2n T (n/2) + nn


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


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


  1 most   of the time, k = 0


                                                      1
7. T (n) = 2T (n/2) + n/ log n


 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) + log n


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) + n log n


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


17. T (n) = 6T (n/3) + n2 log n


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


19. T (n) = 64T (n/8) − n2 log n


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


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


22. T (n) = T (n/2) + n(2 − cos n)



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

  2. T (n) = 4T (n/2) + n2 =⇒ T (n) = Θ(n2 log n) (Case 2)

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

  4. T (n) = 2n T (n/2) + nn =⇒ Does not apply (a is not constant)

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

  6. T (n) = 2T (n/2) + n log n =⇒ T (n) = n log2 n (Case 2)

  7. T (n) = 2T (n/2) + n/ log n =⇒ Does not apply (non-polynomial difference between f (n) and nlogb a )

  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) + log n =⇒ T (n) = Θ( n) (Case 1)

 12. T (n) = 3T (n/2) + n =⇒ T (n) = Θ(nlg 3 ) (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) + n log n =⇒ T (n) = Θ(n log n) (Case 3)

 16. T (n) = 3T (n/3) + n/2 =⇒ T (n) = Θ(n log n) (Case 2)

 17. T (n) = 6T (n/3) + n2 log n =⇒ T (n) = Θ(n2 log n) (Case 3)

 18. T (n) = 4T (n/2) + n/ log n =⇒ T (n) = Θ(n2 ) (Case 1)

 19. T (n) = 64T (n/8) − n2 log n =⇒ 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) + log n =⇒ T (n) = Θ(n2 ) (Case 1)

 22. T (n) = T (n/2) + n(2 − cos n) =⇒ Does not apply. We are in Case 3, but the regularity condition is
     violated. (Consider n = 2πk, where k is odd and arbitrarily large. For any such choice of n, you can
     show that c ≥ 3/2, thereby violating the regularity condition.)



                                                    3

Contenu connexe

Tendances

Tendances (16)

Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Borut Bajc "Asymptotic safety"
Borut Bajc "Asymptotic safety"Borut Bajc "Asymptotic safety"
Borut Bajc "Asymptotic safety"
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
torsionbinormalnotes
torsionbinormalnotestorsionbinormalnotes
torsionbinormalnotes
 
Recurrence relation
Recurrence relationRecurrence relation
Recurrence relation
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
002 ray modeling dynamic systems
002 ray modeling dynamic systems002 ray modeling dynamic systems
002 ray modeling dynamic systems
 
Ps02 cmth03 unit 1
Ps02 cmth03 unit 1Ps02 cmth03 unit 1
Ps02 cmth03 unit 1
 
Sol3
Sol3Sol3
Sol3
 
Recurrence equations
Recurrence equationsRecurrence equations
Recurrence equations
 
Trigo cheat sheet_reduced
Trigo cheat sheet_reducedTrigo cheat sheet_reduced
Trigo cheat sheet_reduced
 
lecture 3
lecture 3lecture 3
lecture 3
 
Unit-1 Classification of Signals
Unit-1 Classification of SignalsUnit-1 Classification of Signals
Unit-1 Classification of Signals
 
Solution 4 i ph o 35
Solution 4 i ph o 35Solution 4 i ph o 35
Solution 4 i ph o 35
 
ENFPC 2012
ENFPC 2012 ENFPC 2012
ENFPC 2012
 
Linear integral equations
Linear integral equationsLinear integral equations
Linear integral equations
 

En vedette

Empaquetar, hacer Cajas Regalos
Empaquetar, hacer Cajas RegalosEmpaquetar, hacer Cajas Regalos
Empaquetar, hacer Cajas Regaloshojita fria
 
Vigencia de la obra "Lecciones orales sobre moral médica" de José Eleuterio G...
Vigencia de la obra "Lecciones orales sobre moral médica" de José Eleuterio G...Vigencia de la obra "Lecciones orales sobre moral médica" de José Eleuterio G...
Vigencia de la obra "Lecciones orales sobre moral médica" de José Eleuterio G...Dr. Jair García-Guerrero
 
Financiando a inovação: uma análise do modelo de venture capital americano e ...
Financiando a inovação: uma análise do modelo de venture capital americano e ...Financiando a inovação: uma análise do modelo de venture capital americano e ...
Financiando a inovação: uma análise do modelo de venture capital americano e ...ekormives
 
Mídias sociais aula 01
Mídias sociais aula 01Mídias sociais aula 01
Mídias sociais aula 01Júlio Rocha
 
Datas das Avaliações
Datas das Avaliações Datas das Avaliações
Datas das Avaliações Dulce Ferreira
 
Software de Aplicación
Software de AplicaciónSoftware de Aplicación
Software de AplicaciónLEITO
 
LILIMARLEN
LILIMARLENLILIMARLEN
LILIMARLENzyanya5
 
Redes informáticas!!!
Redes informáticas!!!Redes informáticas!!!
Redes informáticas!!!cRiS1993
 
Navegando en la Internet
Navegando en la InternetNavegando en la Internet
Navegando en la InternetDámaris Colón
 
crear blog
 crear blog crear blog
crear blogmelfy5
 
Sistemas
SistemasSistemas
Sistemasreymer
 
Humor Grafico
Humor GraficoHumor Grafico
Humor Graficogermanfk
 

En vedette (20)

Mapas Mentales2
Mapas Mentales2Mapas Mentales2
Mapas Mentales2
 
Empaquetar, hacer Cajas Regalos
Empaquetar, hacer Cajas RegalosEmpaquetar, hacer Cajas Regalos
Empaquetar, hacer Cajas Regalos
 
Vigencia de la obra "Lecciones orales sobre moral médica" de José Eleuterio G...
Vigencia de la obra "Lecciones orales sobre moral médica" de José Eleuterio G...Vigencia de la obra "Lecciones orales sobre moral médica" de José Eleuterio G...
Vigencia de la obra "Lecciones orales sobre moral médica" de José Eleuterio G...
 
Financiando a inovação: uma análise do modelo de venture capital americano e ...
Financiando a inovação: uma análise do modelo de venture capital americano e ...Financiando a inovação: uma análise do modelo de venture capital americano e ...
Financiando a inovação: uma análise do modelo de venture capital americano e ...
 
El Cuerpo humano
El Cuerpo humanoEl Cuerpo humano
El Cuerpo humano
 
Fliagalan
FliagalanFliagalan
Fliagalan
 
Mídias sociais aula 01
Mídias sociais aula 01Mídias sociais aula 01
Mídias sociais aula 01
 
Liderança
LiderançaLiderança
Liderança
 
Las Tormentas
Las TormentasLas Tormentas
Las Tormentas
 
Datas das Avaliações
Datas das Avaliações Datas das Avaliações
Datas das Avaliações
 
juannew7@hotmail.com
juannew7@hotmail.comjuannew7@hotmail.com
juannew7@hotmail.com
 
Software de Aplicación
Software de AplicaciónSoftware de Aplicación
Software de Aplicación
 
LILIMARLEN
LILIMARLENLILIMARLEN
LILIMARLEN
 
Redes informáticas!!!
Redes informáticas!!!Redes informáticas!!!
Redes informáticas!!!
 
Navegando en la Internet
Navegando en la InternetNavegando en la Internet
Navegando en la Internet
 
crear blog
 crear blog crear blog
crear blog
 
Diapositivas 2
Diapositivas 2Diapositivas 2
Diapositivas 2
 
Sistemas
SistemasSistemas
Sistemas
 
2ª guerra mundial
2ª guerra mundial2ª guerra mundial
2ª guerra mundial
 
Humor Grafico
Humor GraficoHumor Grafico
Humor Grafico
 

Similaire à Master

Master theorm practive problems with solutions
Master theorm practive problems with solutionsMaster theorm practive problems with solutions
Master theorm practive problems with solutionsKumar
 
Contemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manualContemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manualto2001
 
04_Recurrences_1.ppt
04_Recurrences_1.ppt04_Recurrences_1.ppt
04_Recurrences_1.pptMouDhara1
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrencesMegha V
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxGadaFarhan
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptxdattakumar4
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probabilitybryan111472
 
RecurrenceAndMasterTheorem.ppt
RecurrenceAndMasterTheorem.pptRecurrenceAndMasterTheorem.ppt
RecurrenceAndMasterTheorem.pptISHAN194169
 
Quicksort analysis
Quicksort analysisQuicksort analysis
Quicksort analysisPremjeet Roy
 
Lesson 7: Vector-valued functions
Lesson 7: Vector-valued functionsLesson 7: Vector-valued functions
Lesson 7: Vector-valued functionsMatthew Leingang
 
University of manchester mathematical formula tables
University of manchester mathematical formula tablesUniversity of manchester mathematical formula tables
University of manchester mathematical formula tablesGaurav Vasani
 
Mathematical formula tables
Mathematical formula tablesMathematical formula tables
Mathematical formula tablesSaravana Selvan
 
Elementary Differential Equations 11th Edition Boyce Solutions Manual
Elementary Differential Equations 11th Edition Boyce Solutions ManualElementary Differential Equations 11th Edition Boyce Solutions Manual
Elementary Differential Equations 11th Edition Boyce Solutions ManualMiriamKennedys
 

Similaire à Master (20)

Master theorm practive problems with solutions
Master theorm practive problems with solutionsMaster theorm practive problems with solutions
Master theorm practive problems with solutions
 
Contemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manualContemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manual
 
04_Recurrences_1.ppt
04_Recurrences_1.ppt04_Recurrences_1.ppt
04_Recurrences_1.ppt
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Stirling theorem
Stirling theoremStirling theorem
Stirling theorem
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
 
3.pdf
3.pdf3.pdf
3.pdf
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptx
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
 
RecurrenceAndMasterTheorem.ppt
RecurrenceAndMasterTheorem.pptRecurrenceAndMasterTheorem.ppt
RecurrenceAndMasterTheorem.ppt
 
Quicksort analysis
Quicksort analysisQuicksort analysis
Quicksort analysis
 
Lesson 7: Vector-valued functions
Lesson 7: Vector-valued functionsLesson 7: Vector-valued functions
Lesson 7: Vector-valued functions
 
Chapter6 sampling
Chapter6 samplingChapter6 sampling
Chapter6 sampling
 
University of manchester mathematical formula tables
University of manchester mathematical formula tablesUniversity of manchester mathematical formula tables
University of manchester mathematical formula tables
 
2.pptx
2.pptx2.pptx
2.pptx
 
Radiation
RadiationRadiation
Radiation
 
Mathematical formula tables
Mathematical formula tablesMathematical formula tables
Mathematical formula tables
 
Elementary Differential Equations 11th Edition Boyce Solutions Manual
Elementary Differential Equations 11th Edition Boyce Solutions ManualElementary Differential Equations 11th Edition Boyce Solutions Manual
Elementary Differential Equations 11th Edition Boyce Solutions Manual
 

Plus de Saptarshi Chatterjee (18)

Talon systems - Distributed multi master replication strategy
Talon systems - Distributed multi master replication strategyTalon systems - Distributed multi master replication strategy
Talon systems - Distributed multi master replication strategy
 
System to generate speech to text in real time
System to generate speech to text in real timeSystem to generate speech to text in real time
System to generate speech to text in real time
 
ReactJs Optimizations , Making server side react faster
ReactJs Optimizations , Making server side react faster ReactJs Optimizations , Making server side react faster
ReactJs Optimizations , Making server side react faster
 
Code splitting with server side react
Code splitting with server side reactCode splitting with server side react
Code splitting with server side react
 
Auto generate customized test suit for your AngularJs
Auto generate customized test suit for your AngularJsAuto generate customized test suit for your AngularJs
Auto generate customized test suit for your AngularJs
 
Doc003
Doc003Doc003
Doc003
 
Input02
Input02Input02
Input02
 
Puja 2013
Puja 2013Puja 2013
Puja 2013
 
title
titletitle
title
 
Saptarshi chatterjee-resume
Saptarshi chatterjee-resumeSaptarshi chatterjee-resume
Saptarshi chatterjee-resume
 
SlideShare team outing
SlideShare team outingSlideShare team outing
SlideShare team outing
 
Slide share potluck
Slide share potluckSlide share potluck
Slide share potluck
 
Placement report-2012
Placement report-2012Placement report-2012
Placement report-2012
 
Getting started
Getting startedGetting started
Getting started
 
Trends in online communities
Trends in online communitiesTrends in online communities
Trends in online communities
 
5 x5
5 x55 x5
5 x5
 
Java Teacher in delhi
Java Teacher in delhiJava Teacher in delhi
Java Teacher in delhi
 
Slideshare is now linkedin
Slideshare is now linkedinSlideshare is now linkedin
Slideshare is now linkedin
 

Master

  • 1. 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) where a ≥ 1 and b > 1 are constants and f (n) is an asymptotically positive function. There are 3 cases: 1. If f (n) = O(nlogb a− ) for some constant > 0, then T (n) = Θ(nlogb a ). 2. If f (n) = Θ(nlogb a logk n) with1 k ≥ 0, then T (n) = Θ(nlogb a logk+1 n). 3. If f (n) = Ω(nlogb a+ ) with > 0, and f (n) satisfies the regularity condition, then T (n) = Θ(f (n)). Regularity condition: af (n/b) ≤ cf (n) for some constant c < 1 and all sufficiently large n. Practice Problems For each of the following recurrences, give an expression for the runtime T (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) = 2n T (n/2) + nn 5. T (n) = 16T (n/4) + n 6. T (n) = 2T (n/2) + n log n 1 most of the time, k = 0 1
  • 2. 7. T (n) = 2T (n/2) + n/ log n 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) + log n 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) + n log n 16. T (n) = 3T (n/3) + n/2 17. T (n) = 6T (n/3) + n2 log n 18. T (n) = 4T (n/2) + n/ log n 19. T (n) = 64T (n/8) − n2 log n 20. T (n) = 7T (n/3) + n2 21. T (n) = 4T (n/2) + log n 22. T (n) = T (n/2) + n(2 − cos n) 2
  • 3. Solutions 1. T (n) = 3T (n/2) + n2 =⇒ T (n) = Θ(n2 ) (Case 3) 2. T (n) = 4T (n/2) + n2 =⇒ T (n) = Θ(n2 log n) (Case 2) 3. T (n) = T (n/2) + 2n =⇒ Θ(2n ) (Case 3) 4. T (n) = 2n T (n/2) + nn =⇒ Does not apply (a is not constant) 5. T (n) = 16T (n/4) + n =⇒ T (n) = Θ(n2 ) (Case 1) 6. T (n) = 2T (n/2) + n log n =⇒ T (n) = n log2 n (Case 2) 7. T (n) = 2T (n/2) + n/ log n =⇒ Does not apply (non-polynomial difference between f (n) and nlogb a ) 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) + log n =⇒ T (n) = Θ( n) (Case 1) 12. T (n) = 3T (n/2) + n =⇒ T (n) = Θ(nlg 3 ) (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) + n log n =⇒ T (n) = Θ(n log n) (Case 3) 16. T (n) = 3T (n/3) + n/2 =⇒ T (n) = Θ(n log n) (Case 2) 17. T (n) = 6T (n/3) + n2 log n =⇒ T (n) = Θ(n2 log n) (Case 3) 18. T (n) = 4T (n/2) + n/ log n =⇒ T (n) = Θ(n2 ) (Case 1) 19. T (n) = 64T (n/8) − n2 log n =⇒ 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) + log n =⇒ T (n) = Θ(n2 ) (Case 1) 22. T (n) = T (n/2) + n(2 − cos n) =⇒ Does not apply. We are in Case 3, but the regularity condition is violated. (Consider n = 2πk, where k is odd and arbitrarily large. For any such choice of n, you can show that c ≥ 3/2, thereby violating the regularity condition.) 3