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

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

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.