Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the Lucas numbers: L n = L n - 1 + L n - 2 , n > 1 ; L 1 = 1

Consider the Lucas numbers:
Ln=Ln-1+Ln-2,n>1;L1=1;L0=2
a) Write a recursive function to compute Ln using the above definition directly. Implement your solution and print Li**5, where 0i10, 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 Ln-1 and Ln-2). Implement your solution and print Li**20, where 0i25, as output. This program must be able to compute Ln precisely for n500. Hint 1:
Let Kn=([Ln],[Ln-1]):Kn=([1,1],[1,0])Kn-1,n1;K0=([2],[-1])
With this formulation, design a recursive algorithm for Kn 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 7a) and 7b) 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.
c) Use the Unix time facility (bash time command) to track the time needed for each algorithm. Compare the results and state your conclusion in two or three sentences.
d) Can you use your program in 7 a) to compute L50 if int type of 4 bytes is used? Briefly explain your answer. Explain why your program in 7 b) can computes L500 precisely?
Algorithms and answers for 7 b) to 7 d) should be in asn1 solutions.pdf
For this question, for C++, when compiling option O2 could be considered and a makefile should be written such that the command "make clean" will remove all the "*.o" files, the command "make asn1_a" will generate an executable file "asn1_a" for 7 a) that can be run by typing "asn1_a"; and the command "make asn1.b" will generate an executable file "asn1_b" for 7 b) that can be run by typing "asn1_b". If you are using Java, you may not need the makefile. In that case, you should have shell script files, "asn1_a" and "asn1_b" such that by typing, "asn1_a" and "asn1_b", your java programs will run.
image text in transcribed

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_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

Students also viewed these Databases questions

Question

3. Outline the four major approaches to informative speeches

Answered: 1 week ago

Question

4. Employ strategies to make your audience hungry for information

Answered: 1 week ago