When calculating lucas(8), how many times is lucas(5) calculated?

The Lucas sequence is defined as the sequence that begins with 2 and 1, and every other number in the sequence is the sum
of the two preceding numbers. A recursive method to generate the term in the Lucas sequence is:
```
public int lucas(int n)
{
if(n == 1) return 2;
if(n == 2) return 1;
return lucas(n-1) + lucas(n-2);
}
```

lucas(8) calls lucas(7) and lucas(6). Each of these makes calls also. Here is a partial call tree down to lucas(5):

lucas(8)
/ \
lucas(7) lucas(6)
/ \ / \
lucas(6) lucas(5) lucas(5) lucas(4)

/ \
lucas(5) lucas(4)

There are 3 calls to lucas(5), so lucas (5) is calculated 3 times in the calculation of lucas(8).

Computer Science & Information Technology

You might also like to view...

How is a user slice identified?

A. Solid line border B. Yellow dotted line C. Blue dotted line D. No line

Computer Science & Information Technology

The ____ Tool provides a quick and convenient way to bring professional-looking imagery into your project.

a. Clip Art b. Imagery c. Graphics d. Deco

Computer Science & Information Technology