SlideShare a Scribd company logo
1 of 30
Introduction to Algorithms 6.046J Lecture 2 Prof. Shafi Goldwasser
Solving recurrences ,[object Object],[object Object],[object Object],[object Object]
Recall: Integer Multiplication ,[object Object],[object Object],[object Object],[object Object],[object Object]
Substitution method ,[object Object],[object Object],[object Object],The most general method: Example:   T ( n ) = 4 T ( n /2) + 100 n ,[object Object],[object Object],[object Object],[object Object]
Example of substitution desired   –   residual whenever  ( c /2) n 3  – 100 n     0 , for example, if  c    200  and  n    1 . desired residual 3 3 3 3 3 ) ) 2 / (( ) 2 / ( ) 2 / ( 4 ) 2 / ( 4 ) ( cn 100n n c cn 100n n c 100n n c 100n n T n T          
Example (continued) ,[object Object],[object Object],[object Object],This bound is not tight!
A tighter upper bound? We shall prove that  T ( n ) =  O ( n 2 ) . Assume that  T ( k )     ck 2  for  k  <  n : for  no  choice of  c  > 0 .  Lose! 2 cn   ) 2 / ( 4 ) ( 2 100n cn 100n n T n T    
A tighter upper bound! ,[object Object],[object Object],Inductive hypothesis :  T ( k )     c 1 k 2  –  c 2 k  for  k  <  n . if  c 2  > 100 . Pick  c 1  big enough to handle the initial conditions. ) ( 2 )) 2 / ( ) 2 / ( ( 4 ) 2 / ( 4 ) ( 2 2 1 2 2 2 1 2 2 1 2 2 1 n c n c 100n n c n c n c 100n n c n c 100n n c n c 100n n T n T              
Recursion-tree method ,[object Object],[object Object],[object Object],[object Object]
Example of recursion tree Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 :
Example of recursion tree T ( n ) Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 :
Example of recursion tree n 2 Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 : T ( n /4) T ( n /2)
Example of recursion tree Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 : n 2 ( n /4) 2 ( n /2) 2 T ( n /16) T ( n /8) T ( n /8) T ( n /4)
Example of recursion tree ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2 ( n /2) 2  (1) … Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 : n 2
Example of recursion tree Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 : ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2 ( n /2) 2  (1) … n 2
Example of recursion tree Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 : ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2 ( n /2) 2  (1) … n 2
Example of recursion tree Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 : ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2  (1) … n 2 ( n /2) 2 …
Example of recursion tree Solve  T ( n ) =  T ( n /4) +  T ( n/ 2)  + n 2 : ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2  (1) … … Total  = =   ( n 2 ) n 2 ( n /2) 2 geometric series
Appendix: geometric series Return to last slide viewed. for  | x | < 1 for  x     1
The master method The master method applies to recurrences of the form T ( n ) =  a   T ( n / b ) +  f   ( n )  ,  where  a     1 ,  b  > 1 , and  f   is asymptotically positive.
Idea of master theorem f   ( n/b ) f   ( n/b ) f   ( n/b )   (1) … Recursion tree: … f   ( n ) a f   ( n/b 2 ) f   ( n/b 2 ) f   ( n/b 2 ) … a h  = log b n f   ( n ) a   f   ( n/b ) a 2   f   ( n/b 2 ) … #leaves  =  a h =  a log b n =  n log b a n log b a   (1)
Three common cases Compare  f   ( n )  with  n log b a : ,[object Object],[object Object],[object Object]
Idea of master theorem f   ( n/b ) f   ( n/b ) f   ( n/b )   (1) … Recursion tree: … f   ( n ) a f   ( n/b 2 ) f   ( n/b 2 ) f   ( n/b 2 ) … a h  = log b n f   ( n ) a   f   ( n/b ) a 2   f   ( n/b 2 ) … n log b a   (1) C ASE  1 : The weight increases geometrically from the root to the leaves. The leaves hold a constant fraction of the total weight.  ( n log b a )
Three common cases Compare  f   ( n )  with  n log b a : ,[object Object],[object Object],[object Object]
Idea of master theorem f   ( n/b ) f   ( n/b ) f   ( n/b )   (1) … Recursion tree: … f   ( n ) a f   ( n/b 2 ) f   ( n/b 2 ) f   ( n/b 2 ) … a h  = log b n f   ( n ) a   f   ( n/b ) a 2   f   ( n/b 2 ) … n log b a   (1) C ASE  2 : ( k  = 0 ) The weight is approximately the same on each of the  log b n  levels.  ( n log b a lg   n )
Three common cases (cont.) Compare  f   ( n )  with  n log b a : ,[object Object],[object Object],[object Object],[object Object]
Idea of master theorem f   ( n/b ) f   ( n/b ) f   ( n/b )   (1) … Recursion tree: … f   ( n ) a f   ( n/b 2 ) f   ( n/b 2 ) f   ( n/b 2 ) … a h  = log b n f   ( n ) a   f   ( n/b ) a 2   f   ( n/b 2 ) … n log b a   (1) C ASE  3 : The weight decreases geometrically from the root to the leaves. The root holds a constant fraction of the total weight.  (   f   ( n ))
Examples Ex.  T ( n ) = 4 T ( n /2) +  n a =  4 ,  b  = 2     n log b a  =   n 2 ;  f   ( n ) =  n . C ASE  1 :  f   ( n ) =  O ( n 2   –   )  for    = 1 .    T ( n ) =   ( n 2 ) . Ex.  T ( n ) = 4 T ( n /2) +  n 2 a =  4 ,  b  = 2     n log b a  =   n 2 ;  f   ( n ) =  n 2 .   C ASE  2 :  f   ( n ) =   ( n 2 lg 0 n ) , that is,  k  = 0 .    T ( n ) =   ( n 2 lg   n ) .
Examples Ex.  T ( n ) = 4 T ( n /2) +  n 3 a =  4 ,  b  = 2     n log b a  =   n 2 ;  f   ( n ) =  n 3 .   C ASE  3 :  f   ( n ) =   ( n 2   +   )  for    = 1 and   4( cn /2) 3      cn 3  (reg. cond.) for  c  = 1/2 .    T ( n ) =   ( n 3 ) . Ex.  T ( n ) = 4 T ( n /2) +  n 2 /lg   n a =  4 ,  b  = 2     n log b a  =   n 2 ;  f   ( n ) =  n 2 /lg   n . Master method does not apply.  In particular, for every constant    > 0 , we have  n      (lg   n ) .
Conclusion ,[object Object],[object Object]

More Related Content

What's hot

What's hot (18)

Recurrences
RecurrencesRecurrences
Recurrences
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Master method
Master methodMaster method
Master method
 
Recurrence relation
Recurrence relationRecurrence relation
Recurrence relation
 
Time complexity
Time complexityTime complexity
Time complexity
 
Recurrence relationclass 5
Recurrence relationclass 5Recurrence relationclass 5
Recurrence relationclass 5
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conq
 
Learning object 1
Learning object 1Learning object 1
Learning object 1
 
lecture 4
lecture 4lecture 4
lecture 4
 
big_oh
big_ohbig_oh
big_oh
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Amplitude and Period
Amplitude and PeriodAmplitude and Period
Amplitude and Period
 
ENFPC 2010
ENFPC 2010ENFPC 2010
ENFPC 2010
 
M220w07
M220w07M220w07
M220w07
 
Linear integral equations
Linear integral equationsLinear integral equations
Linear integral equations
 
Amplitude and period
Amplitude and periodAmplitude and period
Amplitude and period
 
Borut Bajc "Asymptotic safety"
Borut Bajc "Asymptotic safety"Borut Bajc "Asymptotic safety"
Borut Bajc "Asymptotic safety"
 

Viewers also liked

Bundler is the Best
Bundler is the BestBundler is the Best
Bundler is the Bestdead_arm
 
Periodic Table Project 2012
Periodic Table Project 2012Periodic Table Project 2012
Periodic Table Project 2012jmori1
 
20087067 choi mun jung final homework.
20087067 choi mun jung final homework.20087067 choi mun jung final homework.
20087067 choi mun jung final homework.문정 최
 
Donor Relationship Management
Donor Relationship Management Donor Relationship Management
Donor Relationship Management Yellow Umbrella
 
Infographic - MSP AWS Migration
Infographic - MSP AWS MigrationInfographic - MSP AWS Migration
Infographic - MSP AWS MigrationCopperEgg
 
Иммуноблисс «скорая помощь» клеткам иммунной системы
Иммуноблисс «скорая помощь» клеткам иммунной системыИммуноблисс «скорая помощь» клеткам иммунной системы
Иммуноблисс «скорая помощь» клеткам иммунной системыЕлена Шальнова
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3Sammi Wilde
 
絕了,能把漢字寫成這樣
絕了,能把漢字寫成這樣絕了,能把漢字寫成這樣
絕了,能把漢字寫成這樣Danny Lin
 
www.tex4future.net: el sector tèxtil 2.0 - Iuris.doc
www.tex4future.net: el sector tèxtil 2.0 - Iuris.docwww.tex4future.net: el sector tèxtil 2.0 - Iuris.doc
www.tex4future.net: el sector tèxtil 2.0 - Iuris.doctex4future
 
ELSA aspects in drug development: Vaccination in pandemic cases / Rational dr...
ELSA aspects in drug development: Vaccination in pandemic cases / Rational dr...ELSA aspects in drug development: Vaccination in pandemic cases / Rational dr...
ELSA aspects in drug development: Vaccination in pandemic cases / Rational dr...Xplore Health
 
Investigate the vaccine for malaria
Investigate the vaccine for malaria  Investigate the vaccine for malaria
Investigate the vaccine for malaria Xplore Health
 
Alternate Concepts, Quotes, ideologies, Ideas of a different kind
Alternate Concepts, Quotes, ideologies, Ideas of a different kindAlternate Concepts, Quotes, ideologies, Ideas of a different kind
Alternate Concepts, Quotes, ideologies, Ideas of a different kindSuraj Mohan
 
London Book Fair 2012: Thinking & Planning the EPUB 3 Way (Slides)
London Book Fair 2012: Thinking & Planning the EPUB 3 Way (Slides)London Book Fair 2012: Thinking & Planning the EPUB 3 Way (Slides)
London Book Fair 2012: Thinking & Planning the EPUB 3 Way (Slides)Datamatics Global Services GmbH
 
Lesson2
Lesson2Lesson2
Lesson2hstryk
 

Viewers also liked (20)

Bundler is the Best
Bundler is the BestBundler is the Best
Bundler is the Best
 
Periodic Table Project 2012
Periodic Table Project 2012Periodic Table Project 2012
Periodic Table Project 2012
 
3 d shape_bingo
3 d shape_bingo3 d shape_bingo
3 d shape_bingo
 
20087067 choi mun jung final homework.
20087067 choi mun jung final homework.20087067 choi mun jung final homework.
20087067 choi mun jung final homework.
 
Donor Relationship Management
Donor Relationship Management Donor Relationship Management
Donor Relationship Management
 
Infographic - MSP AWS Migration
Infographic - MSP AWS MigrationInfographic - MSP AWS Migration
Infographic - MSP AWS Migration
 
Pop
PopPop
Pop
 
Иммуноблисс «скорая помощь» клеткам иммунной системы
Иммуноблисс «скорая помощь» клеткам иммунной системыИммуноблисс «скорая помощь» клеткам иммунной системы
Иммуноблисс «скорая помощь» клеткам иммунной системы
 
Lightning Talk
Lightning TalkLightning Talk
Lightning Talk
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3
 
絕了,能把漢字寫成這樣
絕了,能把漢字寫成這樣絕了,能把漢字寫成這樣
絕了,能把漢字寫成這樣
 
www.tex4future.net: el sector tèxtil 2.0 - Iuris.doc
www.tex4future.net: el sector tèxtil 2.0 - Iuris.docwww.tex4future.net: el sector tèxtil 2.0 - Iuris.doc
www.tex4future.net: el sector tèxtil 2.0 - Iuris.doc
 
Ch04 b
Ch04 bCh04 b
Ch04 b
 
ELSA aspects in drug development: Vaccination in pandemic cases / Rational dr...
ELSA aspects in drug development: Vaccination in pandemic cases / Rational dr...ELSA aspects in drug development: Vaccination in pandemic cases / Rational dr...
ELSA aspects in drug development: Vaccination in pandemic cases / Rational dr...
 
Ds105 2013 ef_ep_a
Ds105 2013 ef_ep_aDs105 2013 ef_ep_a
Ds105 2013 ef_ep_a
 
Investigate the vaccine for malaria
Investigate the vaccine for malaria  Investigate the vaccine for malaria
Investigate the vaccine for malaria
 
Comicus&co
Comicus&coComicus&co
Comicus&co
 
Alternate Concepts, Quotes, ideologies, Ideas of a different kind
Alternate Concepts, Quotes, ideologies, Ideas of a different kindAlternate Concepts, Quotes, ideologies, Ideas of a different kind
Alternate Concepts, Quotes, ideologies, Ideas of a different kind
 
London Book Fair 2012: Thinking & Planning the EPUB 3 Way (Slides)
London Book Fair 2012: Thinking & Planning the EPUB 3 Way (Slides)London Book Fair 2012: Thinking & Planning the EPUB 3 Way (Slides)
London Book Fair 2012: Thinking & Planning the EPUB 3 Way (Slides)
 
Lesson2
Lesson2Lesson2
Lesson2
 

Similar to L2

T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxGadaFarhan
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probabilitybryan111472
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutionssubhashchandra197
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Traian Rebedea
 
Master theorm practive problems with solutions
Master theorm practive problems with solutionsMaster theorm practive problems with solutions
Master theorm practive problems with solutionsKumar
 
Copy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerCopy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerJoepang2015
 
lecture 3
lecture 3lecture 3
lecture 3sajinsc
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquerVikas Sharma
 
RecurrenceAndMasterTheorem.ppt
RecurrenceAndMasterTheorem.pptRecurrenceAndMasterTheorem.ppt
RecurrenceAndMasterTheorem.pptISHAN194169
 
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
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquerKrish_ver2
 
Crib Sheet AP Calculus AB and BC exams
Crib Sheet AP Calculus AB and BC examsCrib Sheet AP Calculus AB and BC exams
Crib Sheet AP Calculus AB and BC examsA Jorge Garcia
 
04_Recurrences_1.ppt
04_Recurrences_1.ppt04_Recurrences_1.ppt
04_Recurrences_1.pptMouDhara1
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms IiSri Prasanna
 

Similar to L2 (20)

T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Master
MasterMaster
Master
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3
 
Master theorm practive problems with solutions
Master theorm practive problems with solutionsMaster theorm practive problems with solutions
Master theorm practive problems with solutions
 
3.pdf
3.pdf3.pdf
3.pdf
 
Copy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerCopy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquer
 
lecture 3
lecture 3lecture 3
lecture 3
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
2.pptx
2.pptx2.pptx
2.pptx
 
RecurrenceAndMasterTheorem.ppt
RecurrenceAndMasterTheorem.pptRecurrenceAndMasterTheorem.ppt
RecurrenceAndMasterTheorem.ppt
 
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
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
03 dc
03 dc03 dc
03 dc
 
Crib Sheet AP Calculus AB and BC exams
Crib Sheet AP Calculus AB and BC examsCrib Sheet AP Calculus AB and BC exams
Crib Sheet AP Calculus AB and BC exams
 
Stirling theorem
Stirling theoremStirling theorem
Stirling theorem
 
04_Recurrences_1.ppt
04_Recurrences_1.ppt04_Recurrences_1.ppt
04_Recurrences_1.ppt
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
 

More from FALLEE31188 (20)

Lecture4
Lecture4Lecture4
Lecture4
 
Lecture2
Lecture2Lecture2
Lecture2
 
L16
L16L16
L16
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Functions
FunctionsFunctions
Functions
 
Field name
Field nameField name
Field name
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Cis068 08
Cis068 08Cis068 08
Cis068 08
 
Chapter14
Chapter14Chapter14
Chapter14
 
Chapt03
Chapt03Chapt03
Chapt03
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C1320prespost
C1320prespostC1320prespost
C1320prespost
 
Brookshear 06
Brookshear 06Brookshear 06
Brookshear 06
 
Book ppt
Book pptBook ppt
Book ppt
 
Assignment 2
Assignment 2Assignment 2
Assignment 2
 
Assignment
AssignmentAssignment
Assignment
 

Recently uploaded

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

L2

  • 1. Introduction to Algorithms 6.046J Lecture 2 Prof. Shafi Goldwasser
  • 2.
  • 3.
  • 4.
  • 5. Example of substitution desired – residual whenever ( c /2) n 3 – 100 n  0 , for example, if c  200 and n  1 . desired residual 3 3 3 3 3 ) ) 2 / (( ) 2 / ( ) 2 / ( 4 ) 2 / ( 4 ) ( cn 100n n c cn 100n n c 100n n c 100n n T n T          
  • 6.
  • 7. A tighter upper bound? We shall prove that T ( n ) = O ( n 2 ) . Assume that T ( k )  ck 2 for k < n : for no choice of c > 0 . Lose! 2 cn   ) 2 / ( 4 ) ( 2 100n cn 100n n T n T    
  • 8.
  • 9.
  • 10. Example of recursion tree Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 :
  • 11. Example of recursion tree T ( n ) Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 :
  • 12. Example of recursion tree n 2 Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 : T ( n /4) T ( n /2)
  • 13. Example of recursion tree Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 : n 2 ( n /4) 2 ( n /2) 2 T ( n /16) T ( n /8) T ( n /8) T ( n /4)
  • 14. Example of recursion tree ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2 ( n /2) 2  (1) … Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 : n 2
  • 15. Example of recursion tree Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 : ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2 ( n /2) 2  (1) … n 2
  • 16. Example of recursion tree Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 : ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2 ( n /2) 2  (1) … n 2
  • 17. Example of recursion tree Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 : ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2  (1) … n 2 ( n /2) 2 …
  • 18. Example of recursion tree Solve T ( n ) = T ( n /4) + T ( n/ 2) + n 2 : ( n /16) 2 ( n /8) 2 ( n /8) 2 ( n /4) 2 ( n /4) 2  (1) … … Total = =  ( n 2 ) n 2 ( n /2) 2 geometric series
  • 19. Appendix: geometric series Return to last slide viewed. for | x | < 1 for x  1
  • 20. The master method The master method applies to recurrences of the form T ( n ) = a T ( n / b ) + f ( n ) , where a  1 , b > 1 , and f is asymptotically positive.
  • 21. Idea of master theorem f ( n/b ) f ( n/b ) f ( n/b )   (1) … Recursion tree: … f ( n ) a f ( n/b 2 ) f ( n/b 2 ) f ( n/b 2 ) … a h = log b n f ( n ) a f ( n/b ) a 2 f ( n/b 2 ) … #leaves = a h = a log b n = n log b a n log b a   (1)
  • 22.
  • 23. Idea of master theorem f ( n/b ) f ( n/b ) f ( n/b )   (1) … Recursion tree: … f ( n ) a f ( n/b 2 ) f ( n/b 2 ) f ( n/b 2 ) … a h = log b n f ( n ) a f ( n/b ) a 2 f ( n/b 2 ) … n log b a   (1) C ASE 1 : The weight increases geometrically from the root to the leaves. The leaves hold a constant fraction of the total weight.  ( n log b a )
  • 24.
  • 25. Idea of master theorem f ( n/b ) f ( n/b ) f ( n/b )   (1) … Recursion tree: … f ( n ) a f ( n/b 2 ) f ( n/b 2 ) f ( n/b 2 ) … a h = log b n f ( n ) a f ( n/b ) a 2 f ( n/b 2 ) … n log b a   (1) C ASE 2 : ( k = 0 ) The weight is approximately the same on each of the log b n levels.  ( n log b a lg n )
  • 26.
  • 27. Idea of master theorem f ( n/b ) f ( n/b ) f ( n/b )   (1) … Recursion tree: … f ( n ) a f ( n/b 2 ) f ( n/b 2 ) f ( n/b 2 ) … a h = log b n f ( n ) a f ( n/b ) a 2 f ( n/b 2 ) … n log b a   (1) C ASE 3 : The weight decreases geometrically from the root to the leaves. The root holds a constant fraction of the total weight.  ( f ( n ))
  • 28. Examples Ex. T ( n ) = 4 T ( n /2) + n a = 4 , b = 2  n log b a = n 2 ; f ( n ) = n . C ASE 1 : f ( n ) = O ( n 2 –  ) for  = 1 .  T ( n ) =  ( n 2 ) . Ex. T ( n ) = 4 T ( n /2) + n 2 a = 4 , b = 2  n log b a = n 2 ; f ( n ) = n 2 . C ASE 2 : f ( n ) =  ( n 2 lg 0 n ) , that is, k = 0 .  T ( n ) =  ( n 2 lg n ) .
  • 29. Examples Ex. T ( n ) = 4 T ( n /2) + n 3 a = 4 , b = 2  n log b a = n 2 ; f ( n ) = n 3 . C ASE 3 : f ( n ) =  ( n 2 +  ) for  = 1 and 4( cn /2) 3  cn 3 (reg. cond.) for c = 1/2 .  T ( n ) =  ( n 3 ) . Ex. T ( n ) = 4 T ( n /2) + n 2 /lg n a = 4 , b = 2  n log b a = n 2 ; f ( n ) = n 2 /lg n . Master method does not apply. In particular, for every constant  > 0 , we have n    (lg n ) .
  • 30.