discrete mathematics in computer science
play

Discrete Mathematics in Computer Science Fibonacci Series - PowerPoint PPT Presentation

Discrete Mathematics in Computer Science Fibonacci Series Generating Functions Malte Helmert, Gabriele R oger University of Basel Revisiting the Fibonacci Series In this section we study generating functions, a powerful method for


  1. Discrete Mathematics in Computer Science Fibonacci Series – Generating Functions Malte Helmert, Gabriele R¨ oger University of Basel

  2. Revisiting the Fibonacci Series In this section we study generating functions, a powerful method for solving recurrences. Generating functions allow us to directly derive closed-form expressions for recurrences. Full mastery of generating functions requires solid knowledge of calculus, in particular power series. Rather than develop the topic in its full depth, we will look at it within the context of a case study, proving the closed form of the Fibonacci series again. We leave out some of the more subtle mathematical aspects, such as the question of convergence of the power series used.

  3. Power Series Definition (power series) Let ( a n ) n ∈ N 0 be a sequence of real numbers. The power series with coefficients ( a n ) is the (possibly partial) function g : R → R defined by ∞ � a n x n g ( x ) = for all x ∈ R . n =0 German: Potenzreihe Notes: more general definitions exist, for example using ( x − c ) n instead of x n for some c ∈ R using complex instead of real numbers using multiple variables

  4. Power Series – Examples n =0 a n x n Reminder: g ( x ) = � ∞ Examples: a n = 1 1 � g ( x ) = 1 − x (only defined for | x | < 1) a n = z n for some z ∈ R 1 � g ( x ) = 1 − zx (only defined for | x | < 1 / | z | ) a n = 1 n ! � g ( x ) = e x (defined for all x ) � 0 x is even a n = ( − 1) ( n − 1) / 2 x is odd n ! � g ( x ) = sin x (defined for all x )

  5. Uniqueness of Power Series Representation Theorem Let g and h be power series with coefficients ( a n ) and ( b n ) . Let ε > 0 such that for all | x | < ε : g and h converge, and g ( x ) = h ( x ) . Then a n = b n for all n ∈ N 0 .

  6. Generating Functions Definition (generating function) Let f : N 0 → R be a function over the natural numbers. The generating function for f is the power series with coefficients ( f ( n )) n ∈ N 0 . German: erzeugende Funktion We are particularly interested in the case where f is defined by a recurrence.

  7. Generating Functions for Solving Recurrences General approach for deriving closed-form expressions for a recurrence f using generating functions: 1 Let g be the generating function of f . 2 Use the recurrence to derive an equation for g . 3 Use algebra and calculus to solve the equation, i.e., derive a closed-form expression for g . 4 Use calculus to derive a power series representation n =0 a n x n for g . � ∞ 5 We get f ( n ) = a n as the closed-form expression of the recurrence.

  8. Case Study: Fibonacci Numbers We now illustrate the approach using the Fibonacci numbers F as an example for the recurrence f . As a reminder, the Fibonacci numbers are defined as follows: F (0) = 0 F (1) = 1 F ( n ) = F ( n − 1) + F ( n − 2) for all n ≥ 2

  9. Case Study: 1. Generating Function 1. Let g be the generating function of f . ∞ � F ( n ) x n g ( x ) = for x ∈ R n =0 Note: The series does not converge for all x , but it converges for | x | < ε for sufficiently small ε > 0. We omit details.

  10. Case Study: 2. Equation for g from Recurrence F (0) = 0 F (1) = 1 F ( n ) = F ( n − 1) + F ( n − 2) for all n ≥ 2 2. Use the recurrence to derive an equation for g . ∞ ∞ F ( n ) x n = 0 · x 0 + 1 · x 1 + � � ( F ( n − 1) + F ( n − 2)) x n g ( x ) = n =0 n =2 ∞ ∞ F ( n − 1) x n + � � F ( n − 2) x n = x + n =2 n =2 ∞ ∞ F ( n ) x n +1 + � � F ( n ) x n +2 = x + n =1 n =0 ∞ ∞ F ( n ) x n + x 2 � � F ( n ) x n = x + x n =1 n =0 ∞ ∞ F ( n ) x n + x 2 � � F ( n ) x n = x + x n =0 n =0 = x + x g ( x ) + x 2 g ( x )

  11. Case Study: 3. Solve Equation for g 3. Use algebra and calculus to solve the equation, i.e., derive a closed-form expression for g . g ( x ) = x + x g ( x ) + x 2 g ( x ) g ( x ) − x g ( x ) − x 2 g ( x ) = x ⇒ g ( x )(1 − x − x 2 ) = x ⇒ x ⇒ g ( x ) = 1 − x − x 2

  12. Case Study: 4. Power Series Representation for g (1) n =0 a n x n for g . 4. Use calculus to derive a power series representation � ∞ 1 x g ( x ) = 1 − x − x 2 = xh ( x ) with h ( x ) = 1 − x − x 2 Idea: partial fraction decomposition, i.e., a b find a , b , α, β such that h ( x ) = 1 − α x + 1 − β x . 1 − β x = a (1 − β x ) + b (1 − α x ) a b 1 − α x + (1 − α x )(1 − β x ) = a − a β x + b − b α x 1 − α x − β x + αβ x 2 = ( a + b ) + ( − a β − b α ) 1 + ( − α − β ) x + αβ x 2 � a + b = 1 , − a β − b α = 0 , − α − β = − 1 , αβ = − 1

  13. Case Study: 4. Power Series Representation for g (2) n =0 a n x n for g . 4. Use calculus to derive a power series representation � ∞ (1) a + b = 1 , (2) − a β − b α = 0 , (3) − α − β = − 1 , (4) αβ = − 1 From (3): (5) β = 1 − α Substituting (5) into (4): α (1 − α ) = − 1 α − α 2 = − 1 ⇒ α 2 − α − 1 = 0 ⇒ � � α = 1 1 4 + 1 = 1 5 ⇒ 2 ± 2 ± 4 √ α = 1 ± 5 ⇒ 2 � The solutions are α = ϕ or α = ψ from the previous chapter. Continue with (6) α = ϕ .

  14. Case Study: 4. Power Series Representation for g (3) n =0 a n x n for g . 4. Use calculus to derive a power series representation � ∞ (1) a + b = 1 , (2) − a β − b α = 0 , (3) − α − β = − 1 , (4) αβ = − 1 , (5) β = 1 − α, (6) α = ϕ Substituting (6) into (5): (7) β = 1 − α = 1 − ϕ = ψ . From (1): (8) b = 1 − a Substituting (6), (7), (8) into (2): − a (1 − ϕ ) − (1 − a ) ϕ = 0 ⇒ − a + a ϕ − ϕ + a ϕ = 0 ⇒ a (2 ϕ − 1) = ϕ ϕ ϕ 1 ⇒ a = 2 ϕ − 1 = √ = √ ϕ 2 · 1 2 (1 + 5) − 1 5

  15. Case Study: 4. Power Series Representation for g (4) n =0 a n x n for g . 4. Use calculus to derive a power series representation � ∞ 1 (8) b = 1 − a , (9) a = 5 ϕ √ Substituting (9) into (8): b = 1 − a = 1 − 1 √ ϕ 5 √ √ 1 2 (1 + 5) 5 = √ − √ 5 5 √ √ = − 1 5 + 1 2 + 1 √ ( − 5) 2 5 √ = − 1 (1 2 − 1 √ 5) 2 5 = − 1 √ ψ 5

  16. Case Study: 4. Power Series Representation for g (5) n =0 a n x n for g . 4. Use calculus to derive a power series representation � ∞ a b g ( x ) = xh ( x ) , h ( x ) = 1 − α x + 1 − β x , 1 b = − 1 α = ϕ, β = ψ, a = 5 ϕ, 5 ψ √ √ Plugging everything in: � 1 � � � 1 − ϕ x − 1 1 1 = x 1 1 g ( x ) = x √ ϕ √ ψ √ ϕ 1 − ϕ x − ψ 1 − ψ x 1 − ψ x 5 5 5 � � ∞ ∞ = x ϕ n x n − ψ � � ψ n x n √ ϕ 5 n =0 n =0 � ∞ � ∞ 1 ϕ n +1 x n +1 − � � ψ n +1 x n +1 = √ 5 n =0 n =0 � ∞ � ∞ ∞ 1 1 ϕ n x n − ( ϕ n − ψ n ) x n � � � ψ n x n √ √ = = 5 5 n =1 n =1 n =1 ∞ 1 ( ϕ n − ψ n ) x n � √ = 5 n =0

  17. Case Study: 5. Extract Closed Form of Recurrence n =0 a n x n for g . 4. Use calculus to derive a power series representation � ∞ 5. We get f ( n ) = a n as the closed-form expression of the recurrence. From ∞ 1 ( ϕ n − ψ n ) x n � √ g ( x ) = 5 n =0 we conclude: 1 ( ϕ n − ψ n ) F ( n ) = √ for all n ∈ N 0 5

  18. Concluding Remarks The approach requires analytical skill, but once understood, it can be applied to many similar recurrences. The same basic idea can be used to solve all recurrences of the form f (0) = a 0 . . . f ( k − 1) = a k − 1 f ( n ) = c 1 f ( n − 1) + · · · + c k f ( n − k ) for all n ≥ k The Fibonacci numbers are the special case where k = 2, a 0 = 0, a 1 = 1, c 1 = 1, c 2 = 1.

  19. Discrete Mathematics in Computer Science Master Theorem for Divide-and-Conquer Recurrences Malte Helmert, Gabriele R¨ oger University of Basel

  20. Divide-and-Conquer Algorithms Recurrences frequently arise in the run-time analysis of divide-and-conquer algorithms. Examples: Mergesort: sort a sequence by recursively sorting two smaller sequences, then merging them Binary search: find an element in a sorted sequence by identifying which half of the sequence must contain the element, then recursively searching it Quickselect: find the k -th smallest element in a sequence by recursive partitioning

  21. Asymptotic Growth Run-time analysis usually focuses on the asymptotic growth rate of run-time. For example, we say “run-time grows at most quadratically” rather than saying that run-time for inputs of size n is 3 n 2 + 17 n + 8. advantages: much simpler to study can abstract from minor implementation details

  22. Big- O , Big-Ω, Big-Θ Definition ( O , Ω, Θ) Let g : R + 0 → R be a function. The sets of functions O ( g ) , Ω( g ) , Θ( g ) are defined as follows: O ( g ) = { f : R + 0 → R | there exist C , n 0 ∈ R s.t. | f ( n ) | ≤ C · g ( n ) for all n ≥ n 0 } Ω( g ) = { f : R + 0 → R | there exist C , n 0 ∈ R s.t. | f ( n ) | ≥ C · g ( n ) for all n ≥ n 0 } Θ( g ) = O ( g ) ∩ Ω( g ) Notation: It is convention to say “5 n 2 + 7 n log 2 n = Θ( n 2 )” instead of “ f ∈ Θ( g ) for the functions f , g with f ( n ) = 5 n 2 + 7 n log 2 n and g ( n ) = n 2 ”. ditto for O , Ω

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend