Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

What tools might be helpful?

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago