SlideShare a Scribd company logo
1 of 10
Download to read offline
Proofs, Recursion and Analysis of
                      Algorithms




                     Mathematical
                     Structures for
                   Computer Science
                               Chapter 2




      Copyright © 2006 W.H. Freeman & Co.
   
   MSCS Slides
   
   Proofs, Recursion and Analysis of
      Algorithms
Monday, February 15, 2010
Properties of recurrence relations
         ●     A linear recurrence relation can be written as
         	

   S(n) = f1(n)S(n-1) + f2(n)S(n-2) + …..+ fk(n)S(n-k) + g(n)
         	

   where f’s and g are or can be expressions involving n.
         ●     Linearity, homogeneity and orders
         ●     A linear relation is when the earlier values in the definition of S(n) as
               shown above have power 1.
                   The term linear means that each term of the sequence is defined as
                   ■


                   a linear function of the preceding terms.
                   ■
                       Example: F(n) = F(n-1) + F(n-2)
         ●     A nonlinear relation is the one that has earlier values in the definition
               as powers other than 1.
                   ■
                       Example: F(n+1) = 2nF(n-1)(1-F(n-1))
                   ■
                       Solutions are quite complex.
         ●     Homogenous relation is a relation that has g(n) = 0 for all n
                   ■
                       Example: a(n) – a(n-1) = 2n
         ●     Inhomogenous relation:	

                   ■
                       Example: S(n) = 2S(n-1)
     Section 2.5                                     Recurrence Relations                 2
Monday, February 15, 2010
Order of Recurrence Relation
         ●     A recurrence relation is said to have constant coefficients if
               the f’s are all constants.
                   ■
                       Fibonaci relation is homogenous and linear:
                        • F(n) = F(n-1) + F(n-2)
                   ■
                       Non-constant coefficients: T(n) = 2nT(n-1) + 3n2T(n-2)

         ●     Order of a relation is defined by the number of previous
               terms in a relation for the nth term.
                   ■
                       First order: S(n) = 2S(n-1)
                        • nth term depends only on term n-1
                   ■
                       Second order: F(n) = F(n-1) + F(n-2)
                        • nth term depends only on term n-1 and n-2
                   ■
                       Third Order: T(n) = 3nT(n-2) + 2T(n-1) + T(n-3)
                        • nth term depends only on term n-1 and n-2 and n-3
     Section 2.5                                   Recurrence Relations        3
Monday, February 15, 2010
Solving recurrence relations
         ●     Solving a recurrence relation employs finding a closed-form
               solution for the recurrence relation.
         ●     An equation such as S(n) = 2n, where we can substitute a value
               for n and get the output value back directly, is called a closed-
               form solution.

         ●     Two methods used to solve a recurrence relation:
                   ■
                       Expand, Guess, Verify
                        • Repeatedly uses the recurrence relation to expand the expression for
                          the nth term until the general pattern can be guessed.
                        • Finally the guess is verified by mathematical induction.
                   ■
                       Solution from a formula
                        • Known solution formulas can be derived for some types of recurrence
                          relations.



     Section 2.5                                      Recurrence Relations                       4
Monday, February 15, 2010
Expand, guess and verify
         ●     Show that S(n) = 2n for the following recurrence relation:
                   S(1) = 2
                   S(n) = 2S(n-1) for n ≥ 2
         ●     Expansion: Using the recurrence relation over again everytime
                   ■
                       S(n) = 2S(n-1)
                   ⇒ S(n) = 2(2S(n-2)) = 22S(n-2)
                   ⇒ S(n) = 22(2S(n-3)) = 23S(n-3)
         ●     Looking at the developing pattern, we guess that after k such
               expansions, the equation has the form
                   ■
                       S(n) = 2kS(n-k)
         ●     This should stop when n-k =1, hence k = n-1,
                   ■
                       As the base case provided is S(1)
         ●     S(n) = 2n-1S(1) ⇒ S(n) = 2*2n-1 = 2n
         ●     Do the verification step by assuming the closed form solution for S(k)
               and proving S(k+1)
     Section 2.5                                     Recurrence Relations              5
Monday, February 15, 2010
Verification Step for Expand, Guess & Verify
         ●     Confirm derived closed-form solution by induction on the value
               of n.
                   ■   Statement to prove: S(n) = 2n for n ≥ 2.
         ●     For the basis step, S(1) = 21. This is true, from the basis step.
         ●     Assume that S(k) = 2k.
         ●     Then S(k+1) = 2S(k) (by using the recurrence relation definition)
                   ■
                     S(k+1) = 2(2k) (by using the above inductive hypothesis)
                   ⇒ S(k+1) = 2k+1
         ●     This proves that our closed-form solution is correct.




     Section 2.5                                  Recurrence Relations             6
Monday, February 15, 2010
Class Exercise
         ●     Find the solution for the following recurrence relation:
                   ■
                       T(1) = 1
                   ■
                       T(n) = T(n-1) + 3 for n ≥ 2




     Section 2.5                                Recurrence Relations      7
Monday, February 15, 2010
Class Exercise
         ●     Find the solution for the following recurrence relation:
                   ■
                       T(1) = 1
                   ■
                       T(n) = T(n-1) + 3 for n ≥ 2
           ●   Solution:
                T(n) = T(n-1) + 3 = [T(n-2)+3] + 3 = T(n-2)+2*3
                	

             = [T(n-3)+3] + 2*3 = T(n-3) + 3*3
                In general, we guess that T(n) = T(n-k) + k*3
                When n-k = 1, i.e. k = n-1
                T(n) = T(1) + (n-1)*3 = 1 + (n-1)*3 = 3(n)-2
                Prove the above by induction: T(1) = 3(1)-2 = 1, true
                Assume T(k) = 3*k-2, show T(k+1) = 3*(k+1) -2 = 3*k+1
                T(k+1) = T(k) + 3 from the given recurrence relation
                T(k+1) = 3*k-2+ 3 by inductive hypothesis
                Hence, T(k+1) = 3*k+1

     Section 2.5                                Recurrence Relations      7
Monday, February 15, 2010
Solution from a formula
         ●   Solution formula for linear first order constant coefficient
             relation

               S(n) = f1(n)S(n-1) + f2(n)S(n-2) + …..+ fk(n)S(n-k) + g(n)
               For the relation S(n) = 2S(n-1), we have f1(n) = 2 and g(n) = 0
               So, S(n) = cS(n-1) + g(n)
               S(n) = c[cS(n-2)+g(n-1)] + g(n) = c[c[cS(n-3)+g(n-2)] + g(n-1)] + g
                  (n)
               .
               S(n) = ckS(n-k) + ck-1g(n-(k-1)) + …..+ cg(n-1) + g(n)
               The lowest value of n-k is 1
               Hence, S(n) = cn-1S(1) + cn-2g(2) + cn-3g(3) +….+ g(n)
                                                        n
                                  S(n) = c   n−1
                                                S(1) + ∑ c n−i g(i)
                                                       i= 2
         ●      For S(n) = 2S(n-1), c = 2 and g(n) = 0
          	

 Hence, S(n) = 2n-1*S(1) = 2.2n-1 = 2n since S(1) = 2
     Section 2.5          €                     Recurrence Relations                 8
Monday, February 15, 2010
Class Exercise
         ●     Show that the solution for the recurrence relation
                   ■
                       S(n) = 2S(n-1) + 3 for n ≥ 2 and given S(1) = 4
                   ■
                       Here, g(n) = 3 and c = 2
                                     S(n) = 2 n +1 + 3[2 n−1 −1]
         ●     given by
         ●     Show that the solution for the recurrence relation
                   ■
                       T(n) = T(n-1) + (n+1) for n ≥ 2 and given T(1) = 2
                          €
                   ■
                       Here, g(n) = 1 and c = n+1
                                     T(n) = 2 n +1 + 3[2 n−1 −1]
         ●     given by

         ●     Solutions for these exercises is in the text (pg. 151-152)
                           €




     Section 2.5                                   Recurrence Relations     9
Monday, February 15, 2010

More Related Content

What's hot

M1 unit iii-jntuworld
M1 unit iii-jntuworldM1 unit iii-jntuworld
M1 unit iii-jntuworld
mrecedu
 
First order linear differential equation
First order linear differential equationFirst order linear differential equation
First order linear differential equation
Nofal Umair
 

What's hot (20)

Add Maths 2
Add Maths 2Add Maths 2
Add Maths 2
 
21 5 ztransform
21 5 ztransform21 5 ztransform
21 5 ztransform
 
LINEAR RECURRENCE RELATIONS WITH CONSTANT COEFFICIENTS
 LINEAR RECURRENCE RELATIONS WITH CONSTANT COEFFICIENTS LINEAR RECURRENCE RELATIONS WITH CONSTANT COEFFICIENTS
LINEAR RECURRENCE RELATIONS WITH CONSTANT COEFFICIENTS
 
0205 ch 2 day 5
0205 ch 2 day 50205 ch 2 day 5
0205 ch 2 day 5
 
Modeling with Recurrence Relations
Modeling with Recurrence RelationsModeling with Recurrence Relations
Modeling with Recurrence Relations
 
presentasi
presentasipresentasi
presentasi
 
M1 unit iii-jntuworld
M1 unit iii-jntuworldM1 unit iii-jntuworld
M1 unit iii-jntuworld
 
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
 
On the stability and accuracy of finite difference method for options pricing
On the stability and accuracy of finite difference method for options pricingOn the stability and accuracy of finite difference method for options pricing
On the stability and accuracy of finite difference method for options pricing
 
Guia edo todas
Guia edo todasGuia edo todas
Guia edo todas
 
Odepowerpointpresentation1
Odepowerpointpresentation1 Odepowerpointpresentation1
Odepowerpointpresentation1
 
Mth3101 Advanced Calculus Chapter 2
Mth3101 Advanced Calculus Chapter 2Mth3101 Advanced Calculus Chapter 2
Mth3101 Advanced Calculus Chapter 2
 
Ecuaciones diferenciales c1
Ecuaciones diferenciales c1Ecuaciones diferenciales c1
Ecuaciones diferenciales c1
 
Funcion gamma
Funcion gammaFuncion gamma
Funcion gamma
 
Recurrence relations
Recurrence relationsRecurrence relations
Recurrence relations
 
Day 03
Day 03Day 03
Day 03
 
Differential equations
Differential equationsDifferential equations
Differential equations
 
Lohans’ magic squares and the Gaussian elimination method
Lohans’ magic squares and the Gaussian elimination methodLohans’ magic squares and the Gaussian elimination method
Lohans’ magic squares and the Gaussian elimination method
 
Estimation and Prediction of Complex Systems: Progress in Weather and Climate
Estimation and Prediction of Complex Systems: Progress in Weather and ClimateEstimation and Prediction of Complex Systems: Progress in Weather and Climate
Estimation and Prediction of Complex Systems: Progress in Weather and Climate
 
First order linear differential equation
First order linear differential equationFirst order linear differential equation
First order linear differential equation
 

Similar to CPSC 125 Ch 2 Sec 5

lecture 3
lecture 3lecture 3
lecture 3
sajinsc
 
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
RishikeshJha33
 
CPSC 125 Ch 4 Sec 1
CPSC 125 Ch 4 Sec 1CPSC 125 Ch 4 Sec 1
CPSC 125 Ch 4 Sec 1
David Wood
 
Cpsc125 Ch4 Sec1
Cpsc125 Ch4 Sec1Cpsc125 Ch4 Sec1
Cpsc125 Ch4 Sec1
David Wood
 
Solving systems of equations algebraically 2
Solving systems of equations algebraically 2Solving systems of equations algebraically 2
Solving systems of equations algebraically 2
Anthony_Maiorano
 
Ppt formula for sum of series
Ppt  formula for sum of seriesPpt  formula for sum of series
Ppt formula for sum of series
manojsweet
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
Sri Prasanna
 

Similar to CPSC 125 Ch 2 Sec 5 (20)

lecture 3
lecture 3lecture 3
lecture 3
 
CPSC 125 Ch 2 Sec 4
CPSC 125 Ch 2 Sec 4CPSC 125 Ch 2 Sec 4
CPSC 125 Ch 2 Sec 4
 
Time complexity
Time complexityTime complexity
Time complexity
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
S 7
S 7S 7
S 7
 
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
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabist
 
Monopole zurich
Monopole zurichMonopole zurich
Monopole zurich
 
CPSC 125 Ch 4 Sec 1
CPSC 125 Ch 4 Sec 1CPSC 125 Ch 4 Sec 1
CPSC 125 Ch 4 Sec 1
 
Cpsc125 Ch4 Sec1
Cpsc125 Ch4 Sec1Cpsc125 Ch4 Sec1
Cpsc125 Ch4 Sec1
 
Dsp lecture vol 2 dft & fft
Dsp lecture vol 2 dft & fftDsp lecture vol 2 dft & fft
Dsp lecture vol 2 dft & fft
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptx
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
recurence solutions
recurence solutionsrecurence solutions
recurence solutions
 
Solving systems of equations algebraically 2
Solving systems of equations algebraically 2Solving systems of equations algebraically 2
Solving systems of equations algebraically 2
 
Ppt formula for sum of series
Ppt  formula for sum of seriesPpt  formula for sum of series
Ppt formula for sum of series
 
Session 20
Session 20Session 20
Session 20
 
Analysis Of Algorithms Ii
Analysis Of Algorithms IiAnalysis Of Algorithms Ii
Analysis Of Algorithms Ii
 

More from David Wood

Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsMeditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
David Wood
 
Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926
David Wood
 
Introduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesIntroduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF Vocabularies
David Wood
 

More from David Wood (20)

Internet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchainInternet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchain
 
Returning to Online Privacy?
Returning to Online Privacy?Returning to Online Privacy?
Returning to Online Privacy?
 
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
 
BlockSW 2019 Keynote
BlockSW 2019 KeynoteBlockSW 2019 Keynote
BlockSW 2019 Keynote
 
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
 
Privacy in the Smart City
Privacy in the Smart CityPrivacy in the Smart City
Privacy in the Smart City
 
Controlling Complexities in Software Development
Controlling Complexities in Software DevelopmentControlling Complexities in Software Development
Controlling Complexities in Software Development
 
Privacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable ClaimsPrivacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable Claims
 
Implementing the Verifiable Claims data model
Implementing the Verifiable Claims data modelImplementing the Verifiable Claims data model
Implementing the Verifiable Claims data model
 
So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301
 
Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601
 
When Metaphors Kill
When Metaphors KillWhen Metaphors Kill
When Metaphors Kill
 
Secularism in Australia
Secularism in AustraliaSecularism in Australia
Secularism in Australia
 
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsMeditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
 
Building a writer's platform with social media
Building a writer's platform with social mediaBuilding a writer's platform with social media
Building a writer's platform with social media
 
Summary of the Hero's Journey
Summary of the Hero's JourneySummary of the Hero's Journey
Summary of the Hero's Journey
 
Open by Default
Open by DefaultOpen by Default
Open by Default
 
Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926
 
Linked Data ROI 20110426
Linked Data ROI 20110426Linked Data ROI 20110426
Linked Data ROI 20110426
 
Introduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesIntroduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF Vocabularies
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

CPSC 125 Ch 2 Sec 5

  • 1. Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co. MSCS Slides Proofs, Recursion and Analysis of Algorithms Monday, February 15, 2010
  • 2. Properties of recurrence relations ● A linear recurrence relation can be written as S(n) = f1(n)S(n-1) + f2(n)S(n-2) + …..+ fk(n)S(n-k) + g(n) where f’s and g are or can be expressions involving n. ● Linearity, homogeneity and orders ● A linear relation is when the earlier values in the definition of S(n) as shown above have power 1. The term linear means that each term of the sequence is defined as ■ a linear function of the preceding terms. ■ Example: F(n) = F(n-1) + F(n-2) ● A nonlinear relation is the one that has earlier values in the definition as powers other than 1. ■ Example: F(n+1) = 2nF(n-1)(1-F(n-1)) ■ Solutions are quite complex. ● Homogenous relation is a relation that has g(n) = 0 for all n ■ Example: a(n) – a(n-1) = 2n ● Inhomogenous relation: ■ Example: S(n) = 2S(n-1) Section 2.5 Recurrence Relations 2 Monday, February 15, 2010
  • 3. Order of Recurrence Relation ● A recurrence relation is said to have constant coefficients if the f’s are all constants. ■ Fibonaci relation is homogenous and linear: • F(n) = F(n-1) + F(n-2) ■ Non-constant coefficients: T(n) = 2nT(n-1) + 3n2T(n-2) ● Order of a relation is defined by the number of previous terms in a relation for the nth term. ■ First order: S(n) = 2S(n-1) • nth term depends only on term n-1 ■ Second order: F(n) = F(n-1) + F(n-2) • nth term depends only on term n-1 and n-2 ■ Third Order: T(n) = 3nT(n-2) + 2T(n-1) + T(n-3) • nth term depends only on term n-1 and n-2 and n-3 Section 2.5 Recurrence Relations 3 Monday, February 15, 2010
  • 4. Solving recurrence relations ● Solving a recurrence relation employs finding a closed-form solution for the recurrence relation. ● An equation such as S(n) = 2n, where we can substitute a value for n and get the output value back directly, is called a closed- form solution. ● Two methods used to solve a recurrence relation: ■ Expand, Guess, Verify • Repeatedly uses the recurrence relation to expand the expression for the nth term until the general pattern can be guessed. • Finally the guess is verified by mathematical induction. ■ Solution from a formula • Known solution formulas can be derived for some types of recurrence relations. Section 2.5 Recurrence Relations 4 Monday, February 15, 2010
  • 5. Expand, guess and verify ● Show that S(n) = 2n for the following recurrence relation: S(1) = 2 S(n) = 2S(n-1) for n ≥ 2 ● Expansion: Using the recurrence relation over again everytime ■ S(n) = 2S(n-1) ⇒ S(n) = 2(2S(n-2)) = 22S(n-2) ⇒ S(n) = 22(2S(n-3)) = 23S(n-3) ● Looking at the developing pattern, we guess that after k such expansions, the equation has the form ■ S(n) = 2kS(n-k) ● This should stop when n-k =1, hence k = n-1, ■ As the base case provided is S(1) ● S(n) = 2n-1S(1) ⇒ S(n) = 2*2n-1 = 2n ● Do the verification step by assuming the closed form solution for S(k) and proving S(k+1) Section 2.5 Recurrence Relations 5 Monday, February 15, 2010
  • 6. Verification Step for Expand, Guess & Verify ● Confirm derived closed-form solution by induction on the value of n. ■ Statement to prove: S(n) = 2n for n ≥ 2. ● For the basis step, S(1) = 21. This is true, from the basis step. ● Assume that S(k) = 2k. ● Then S(k+1) = 2S(k) (by using the recurrence relation definition) ■ S(k+1) = 2(2k) (by using the above inductive hypothesis) ⇒ S(k+1) = 2k+1 ● This proves that our closed-form solution is correct. Section 2.5 Recurrence Relations 6 Monday, February 15, 2010
  • 7. Class Exercise ● Find the solution for the following recurrence relation: ■ T(1) = 1 ■ T(n) = T(n-1) + 3 for n ≥ 2 Section 2.5 Recurrence Relations 7 Monday, February 15, 2010
  • 8. Class Exercise ● Find the solution for the following recurrence relation: ■ T(1) = 1 ■ T(n) = T(n-1) + 3 for n ≥ 2 ● Solution: T(n) = T(n-1) + 3 = [T(n-2)+3] + 3 = T(n-2)+2*3 = [T(n-3)+3] + 2*3 = T(n-3) + 3*3 In general, we guess that T(n) = T(n-k) + k*3 When n-k = 1, i.e. k = n-1 T(n) = T(1) + (n-1)*3 = 1 + (n-1)*3 = 3(n)-2 Prove the above by induction: T(1) = 3(1)-2 = 1, true Assume T(k) = 3*k-2, show T(k+1) = 3*(k+1) -2 = 3*k+1 T(k+1) = T(k) + 3 from the given recurrence relation T(k+1) = 3*k-2+ 3 by inductive hypothesis Hence, T(k+1) = 3*k+1 Section 2.5 Recurrence Relations 7 Monday, February 15, 2010
  • 9. Solution from a formula ● Solution formula for linear first order constant coefficient relation S(n) = f1(n)S(n-1) + f2(n)S(n-2) + …..+ fk(n)S(n-k) + g(n) For the relation S(n) = 2S(n-1), we have f1(n) = 2 and g(n) = 0 So, S(n) = cS(n-1) + g(n) S(n) = c[cS(n-2)+g(n-1)] + g(n) = c[c[cS(n-3)+g(n-2)] + g(n-1)] + g (n) . S(n) = ckS(n-k) + ck-1g(n-(k-1)) + …..+ cg(n-1) + g(n) The lowest value of n-k is 1 Hence, S(n) = cn-1S(1) + cn-2g(2) + cn-3g(3) +….+ g(n) n S(n) = c n−1 S(1) + ∑ c n−i g(i) i= 2 ● For S(n) = 2S(n-1), c = 2 and g(n) = 0 Hence, S(n) = 2n-1*S(1) = 2.2n-1 = 2n since S(1) = 2 Section 2.5 € Recurrence Relations 8 Monday, February 15, 2010
  • 10. Class Exercise ● Show that the solution for the recurrence relation ■ S(n) = 2S(n-1) + 3 for n ≥ 2 and given S(1) = 4 ■ Here, g(n) = 3 and c = 2 S(n) = 2 n +1 + 3[2 n−1 −1] ● given by ● Show that the solution for the recurrence relation ■ T(n) = T(n-1) + (n+1) for n ≥ 2 and given T(1) = 2 € ■ Here, g(n) = 1 and c = n+1 T(n) = 2 n +1 + 3[2 n−1 −1] ● given by ● Solutions for these exercises is in the text (pg. 151-152) € Section 2.5 Recurrence Relations 9 Monday, February 15, 2010