SlideShare a Scribd company logo
1 of 11
Introduction to Algorithms
Chapter 4: Recurrences
2
Solving Recurrences
 A recurrence is an equation that describes a
function in terms of itself by using smaller inputs
 The expression:
 Describes the running time for a function contains
recursion.

















1
2
2
1
)
(
n
cn
n
T
n
c
n
T
3
Solving Recurrences
 Examples:
 T(n) = 2T(n/2) + (n)  T(n) = (n lg n)
 T(n) = 2T(n/2) + n  T(n) = (n lg n)
 T(n) = 2T(n/2) + 17 + n  T(n) = (n lg n)
 Three methods for solving recurrences
 Substitution method
 Iteration method
 Master method
4
Recurrence Examples








0
0
)
1
(
0
)
(
n
n
n
T
c
n
T

















1
2
2
1
)
(
n
c
n
T
n
c
n
T

















1
1
)
(
n
cn
b
n
aT
n
c
n
T








0
)
1
(
0
0
)
(
n
n
T
n
n
n
T
5
Substitution Method
 The substitution method
 “making a good guess method”
 Guess the form of the answer, then
 use induction to find the constants and show
that solution works
 Our goal: show that
T(n) = 2T(n/2) + n = O(n lg n)
6
Substitution Method
T(n) = 2T(n/2) + n = O(n lg n)
 Thus, we need to show that T(n)  c n lg n
with an appropriate choice of c
 Inductive hypothesis: assume
T(n/2)  c (n/2) lg (n/2)
 Substitute back into recurrence to show that
T(n)  c n lg n follows, when c  1
 T(n) = 2 T(n/2) + n
 2 (c (n/2) lg (n/2)) + n
= cn lg(n/2) + n
= cn lg n – cn lg 2 + n
= cn lg n – cn + n
 cn lg n for c  1
= O(n lg n) for c  1
8
Iteration Method
 Iteration method:
 Expand the recurrence k times
 Work some algebra to express as a
summation
 Evaluate the summation
9
 T(n) = c + T(n-1) = c + c + T(n-2)
= 2c + T(n-2) = 2c + c + T(n-3)
= 3c + T(n-3) … kc + T(n-k)
= ck + T(n-k)
 So far for n  k we have
 T(n) = ck + T(n-k)
 To stop the recursion, we should have
 n - k = 0  k = n
 T(n) = cn + T(0) = cn
 Thus in general T(n) = O(n)








0
)
1
(
0
0
)
(
n
n
T
c
n
n
T
10
 T(n) = n + T(n-1)
= n + n-1 + T(n-2)
= n + n-1 + n-2 + T(n-3)
= n + n-1 + n-2 + n-3 + T(n-4)
= …
= n + n-1 + n-2 + n-3 + … + (n-k+1) + T(n-k)
= for n  k
 To stop the recursion, we should have n - k = 0  k = n








0
)
1
(
0
0
)
(
n
n
T
n
n
n
T
)
(
1
k
n
T
i
n
k
n
i





2
1
0
)
0
(
1
1




 
 

n
n
i
T
i
n
i
n
i
)
(
2
1
)
( 2
n
O
n
n
n
T 


11
 T(n) = 2 T(n/2) + c 1
= 2(2 T(n/2/2) + c) + c 2
= 22 T(n/22) + 2c + c
= 22(2 T(n/22/2) + c) + (22-1)c 3
= 23 T(n/23) + 4c + 3c
= 23 T(n/23) + (23-1)c
= 23(2 T(n/23/2) + c) + 7c 4
= 24 T(n/24) + (24-1)c
= …
= 2k T(n/2k) + (2k - 1)c k














 1
2
2
1
)
( n
c
n
T
n
c
n
T
12
 So far for n  k we have
 T(n) = 2k T(n/2k) + (2k - 1)c
 To stop the recursion, we should have
 n/2k = 1  n = 2k  k = lg n
 T(n) = n T(n/n) + (n - 1)c
= n T(1) + (n-1)c
= nc + (n-1)c
= nc + nc – c = 2cn – c
T(n) = 2cn – c = O(n)














 1
2
2
1
)
( n
c
n
T
n
c
n
T

More Related Content

Similar to 04_Recurrences_1.ppt

lecture 3
lecture 3lecture 3
lecture 3sajinsc
 
Master theorm practive problems with solutions
Master theorm practive problems with solutionsMaster theorm practive problems with solutions
Master theorm practive problems with solutionsKumar
 
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdfRishikeshJha33
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probabilitybryan111472
 
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
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutionssubhashchandra197
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqPradeep Bisht
 
signals and systems_isooperations.pptx
signals and   systems_isooperations.pptxsignals and   systems_isooperations.pptx
signals and systems_isooperations.pptxMrFanatic1
 
RECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMRECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMAlpana Ingale
 
Quicksort analysis
Quicksort analysisQuicksort analysis
Quicksort analysisPremjeet Roy
 
Recurrence relationclass 5
Recurrence relationclass 5Recurrence relationclass 5
Recurrence relationclass 5Kumar
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Traian Rebedea
 
Lesson 7: Vector-valued functions
Lesson 7: Vector-valued functionsLesson 7: Vector-valued functions
Lesson 7: Vector-valued functionsMatthew Leingang
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptxdattakumar4
 

Similar to 04_Recurrences_1.ppt (20)

lecture 3
lecture 3lecture 3
lecture 3
 
Master
MasterMaster
Master
 
Master method
Master methodMaster method
Master method
 
Master theorm practive problems with solutions
Master theorm practive problems with solutionsMaster theorm practive problems with solutions
Master theorm practive problems with solutions
 
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
 
Recurrences
RecurrencesRecurrences
Recurrences
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
 
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
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
Computer science-formulas
Computer science-formulasComputer science-formulas
Computer science-formulas
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conq
 
signals and systems_isooperations.pptx
signals and   systems_isooperations.pptxsignals and   systems_isooperations.pptx
signals and systems_isooperations.pptx
 
RECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMRECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEM
 
Quicksort analysis
Quicksort analysisQuicksort analysis
Quicksort analysis
 
Recurrence relationclass 5
Recurrence relationclass 5Recurrence relationclass 5
Recurrence relationclass 5
 
L2
L2L2
L2
 
2.pptx
2.pptx2.pptx
2.pptx
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3
 
Lesson 7: Vector-valued functions
Lesson 7: Vector-valued functionsLesson 7: Vector-valued functions
Lesson 7: Vector-valued functions
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptx
 

More from MouDhara1

datacommunicationnetworking-161025074805.pptx
datacommunicationnetworking-161025074805.pptxdatacommunicationnetworking-161025074805.pptx
datacommunicationnetworking-161025074805.pptxMouDhara1
 
06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptxMouDhara1
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptxMouDhara1
 
lecture-i-trees.ppt
lecture-i-trees.pptlecture-i-trees.ppt
lecture-i-trees.pptMouDhara1
 
JSP-Servlet.ppt
JSP-Servlet.pptJSP-Servlet.ppt
JSP-Servlet.pptMouDhara1
 
09 Structures in C.pptx
09 Structures in C.pptx09 Structures in C.pptx
09 Structures in C.pptxMouDhara1
 
Chapter 12 - Heaps.ppt
Chapter 12 - Heaps.pptChapter 12 - Heaps.ppt
Chapter 12 - Heaps.pptMouDhara1
 
javascript12.pptx
javascript12.pptxjavascript12.pptx
javascript12.pptxMouDhara1
 
Linked list.pptx
Linked list.pptxLinked list.pptx
Linked list.pptxMouDhara1
 
For Client vs.pptx
For Client vs.pptxFor Client vs.pptx
For Client vs.pptxMouDhara1
 
Form tag.pptx
Form tag.pptxForm tag.pptx
Form tag.pptxMouDhara1
 
Web technology.pptx
Web technology.pptxWeb technology.pptx
Web technology.pptxMouDhara1
 
web tech.pptx
web tech.pptxweb tech.pptx
web tech.pptxMouDhara1
 
Introduction to Data Structure.pptx
Introduction to Data Structure.pptxIntroduction to Data Structure.pptx
Introduction to Data Structure.pptxMouDhara1
 

More from MouDhara1 (20)

ppt_dcn.pdf
ppt_dcn.pdfppt_dcn.pdf
ppt_dcn.pdf
 
datacommunicationnetworking-161025074805.pptx
datacommunicationnetworking-161025074805.pptxdatacommunicationnetworking-161025074805.pptx
datacommunicationnetworking-161025074805.pptx
 
06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptx
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
 
lecture-i-trees.ppt
lecture-i-trees.pptlecture-i-trees.ppt
lecture-i-trees.ppt
 
JSP-Servlet.ppt
JSP-Servlet.pptJSP-Servlet.ppt
JSP-Servlet.ppt
 
09 Structures in C.pptx
09 Structures in C.pptx09 Structures in C.pptx
09 Structures in C.pptx
 
Chapter 12 - Heaps.ppt
Chapter 12 - Heaps.pptChapter 12 - Heaps.ppt
Chapter 12 - Heaps.ppt
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
DTD1.pptx
DTD1.pptxDTD1.pptx
DTD1.pptx
 
STACK1.pptx
STACK1.pptxSTACK1.pptx
STACK1.pptx
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
javascript12.pptx
javascript12.pptxjavascript12.pptx
javascript12.pptx
 
Linked list.pptx
Linked list.pptxLinked list.pptx
Linked list.pptx
 
For Client vs.pptx
For Client vs.pptxFor Client vs.pptx
For Client vs.pptx
 
Form tag.pptx
Form tag.pptxForm tag.pptx
Form tag.pptx
 
Web technology.pptx
Web technology.pptxWeb technology.pptx
Web technology.pptx
 
cse.pptx
cse.pptxcse.pptx
cse.pptx
 
web tech.pptx
web tech.pptxweb tech.pptx
web tech.pptx
 
Introduction to Data Structure.pptx
Introduction to Data Structure.pptxIntroduction to Data Structure.pptx
Introduction to Data Structure.pptx
 

Recently uploaded

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptxrouholahahmadi9876
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...vershagrag
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Ramkumar k
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 

Recently uploaded (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 

04_Recurrences_1.ppt

  • 2. 2 Solving Recurrences  A recurrence is an equation that describes a function in terms of itself by using smaller inputs  The expression:  Describes the running time for a function contains recursion.                  1 2 2 1 ) ( n cn n T n c n T
  • 3. 3 Solving Recurrences  Examples:  T(n) = 2T(n/2) + (n)  T(n) = (n lg n)  T(n) = 2T(n/2) + n  T(n) = (n lg n)  T(n) = 2T(n/2) + 17 + n  T(n) = (n lg n)  Three methods for solving recurrences  Substitution method  Iteration method  Master method
  • 5. 5 Substitution Method  The substitution method  “making a good guess method”  Guess the form of the answer, then  use induction to find the constants and show that solution works  Our goal: show that T(n) = 2T(n/2) + n = O(n lg n)
  • 6. 6 Substitution Method T(n) = 2T(n/2) + n = O(n lg n)  Thus, we need to show that T(n)  c n lg n with an appropriate choice of c  Inductive hypothesis: assume T(n/2)  c (n/2) lg (n/2)  Substitute back into recurrence to show that T(n)  c n lg n follows, when c  1  T(n) = 2 T(n/2) + n  2 (c (n/2) lg (n/2)) + n = cn lg(n/2) + n = cn lg n – cn lg 2 + n = cn lg n – cn + n  cn lg n for c  1 = O(n lg n) for c  1
  • 7. 8 Iteration Method  Iteration method:  Expand the recurrence k times  Work some algebra to express as a summation  Evaluate the summation
  • 8. 9  T(n) = c + T(n-1) = c + c + T(n-2) = 2c + T(n-2) = 2c + c + T(n-3) = 3c + T(n-3) … kc + T(n-k) = ck + T(n-k)  So far for n  k we have  T(n) = ck + T(n-k)  To stop the recursion, we should have  n - k = 0  k = n  T(n) = cn + T(0) = cn  Thus in general T(n) = O(n)         0 ) 1 ( 0 0 ) ( n n T c n n T
  • 9. 10  T(n) = n + T(n-1) = n + n-1 + T(n-2) = n + n-1 + n-2 + T(n-3) = n + n-1 + n-2 + n-3 + T(n-4) = … = n + n-1 + n-2 + n-3 + … + (n-k+1) + T(n-k) = for n  k  To stop the recursion, we should have n - k = 0  k = n         0 ) 1 ( 0 0 ) ( n n T n n n T ) ( 1 k n T i n k n i      2 1 0 ) 0 ( 1 1          n n i T i n i n i ) ( 2 1 ) ( 2 n O n n n T   
  • 10. 11  T(n) = 2 T(n/2) + c 1 = 2(2 T(n/2/2) + c) + c 2 = 22 T(n/22) + 2c + c = 22(2 T(n/22/2) + c) + (22-1)c 3 = 23 T(n/23) + 4c + 3c = 23 T(n/23) + (23-1)c = 23(2 T(n/23/2) + c) + 7c 4 = 24 T(n/24) + (24-1)c = … = 2k T(n/2k) + (2k - 1)c k                1 2 2 1 ) ( n c n T n c n T
  • 11. 12  So far for n  k we have  T(n) = 2k T(n/2k) + (2k - 1)c  To stop the recursion, we should have  n/2k = 1  n = 2k  k = lg n  T(n) = n T(n/n) + (n - 1)c = n T(1) + (n-1)c = nc + (n-1)c = nc + nc – c = 2cn – c T(n) = 2cn – c = O(n)                1 2 2 1 ) ( n c n T n c n T