Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

8. Consider the Lucas numbers: Ln = Ln1 + Ln-2, n > 1; L1 = 1; Lo = 2. a). Write a recursive function

 

8. Consider the Lucas numbers: Ln = Ln1 + Ln-2, n > 1; L1 = 1; Lo = 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 com- plexity of adding Ln-1 and Ln-2). 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 Gn Gn = ( L ) : G = (1 1) Gn-1, n > 1; G = Go 0 ( 12 ) ; G = ( 2 1 ) -1 = Ln Ln-1 With this formulation, design a recursive algorithm for G such that the algorithm will return both Ln and Ln-1 with input parameter n. Hint 2: Can you use a primitive type to store L500? For programs in 8 a) and 8 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 data type or object, if needed.

Step by Step Solution

3.48 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

a Here is a recursive function in Java to compute the Lucas n... 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_2

Step: 3

blur-text-image_3

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

Calculus For Business, Economics And The Social And Life Sciences

Authors: Laurence Hoffmann, Gerald Bradley, David Sobecki, Michael Price

11th Brief Edition

978-0073532387, 007353238X

More Books

Students also viewed these Programming questions

Question

Determine miller indices of plane X z 2/3 90% a/3

Answered: 1 week ago