VOOZH about

URL: https://www.geeksforgeeks.org/dsa/leonardo-number/

⇱ Leonardo Number - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Leonardo Number

Last Updated : 28 Mar, 2023

The Leonardo numbers are a sequence of numbers given by the recurrence: 

The first few Leonardo Numbers are 1, 1, 3, 5, 9, 15, 25, 41, 67, 109, 177, 287, 465, 753, 1219, 1973, 3193, 5167, 8361, ··· 
The Leonardo numbers are related to the Fibonacci numbers by below relation:

Given a number n, find n-th Leonardo number. 

Examples:  

Input : n = 0
Output : 1

Input : n = 3
Output : 5

A simple solution is to recursively compute values.  

Output : 

5

Time Complexity: Exponential
Auxiliary Space: O(n) because the function call stack grows linearly with the input n. Each function call adds a new frame to the call stack, which contains local variables and the return address.

A better solution is to use dynamic programming.  

Output :  

5


Time Complexity: O(n)
Auxiliary Space: O(n) where n is the input number. This is because dp array has been created of size n+1.


The best solution is to use relation with Fibonacci Numbers. We can find the n-th Fibonacci number in O(Log n) time [See method 4 of this]  

Output : 

5


Time Complexity : O(Log n)
 

Comment
Article Tags:
Article Tags: