Question: Consider following recursive method and answer the questions. public int luc(int n) { if(n == 1) return 2; if(n == 2) return 1; return luc(n-1)

Consider following recursive method and answer the questions.

public int luc(int n) {

if(n == 1) return 2;

if(n == 2) return 1;

return luc(n-1) + luc(n-2);

}

a) what does this method do?

b) compute and trace luc(8)

c) In part b, how many times luc(5) calculated?

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!