Question: 7 . Consider the Lucas numbers: Ln = Ln 1 + Ln 2 , n > 1 ; L 1 = 1 ; L 0

7. Consider the Lucas numbers:
Ln = Ln1+ Ln2, n >1; L1=1; L0=2.
a) Write a recursive function to compute Ln using the above definition directly. Implement
your solution and print Li5, where 0<= i <=10, as output.
b) Write a recursive function/procedure to compute Ln with time complexity O(n)(more
precisely, the time complexity should be O(nA(n)) when n is large, where A(n) is the
complexity of adding Ln1 and Ln2). Implement your solution and print Li20, where
0<= i <=25, as output. This program must be able to compute Ln precisely for n <=500.
Hint 1:
Let Kn =
Ln
Ln1
: Kn =
11
10
\times Kn1, n >=1; K0=
2
1
With this formulation, design a recursive algorithm for Kn such that the algorithm will
return both Ln and Ln1 with input parameter n.
Hint 2: Can you use a primitive type to store L500?
For programs in 7 a) and 7 b) of this question, you are NOT allowed to use Python. For
C++ and Java, you can only use primitive types such as char, int, long and long long.
You are not allowed to use large integer, such as BigInteger in Java, from the language
library. You have to write your own large integer class or data type, if needed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!