3. A function f takes an integer argument n and returns an
integer.
• If n < 2, the value of f(n) is n + 1.
• If n > 2, the value of f(n) is f(n - 1) * f(n - 2) + f(n -
2).
There are three parts to the question.
(a) Write out the value of f(0), f(1), f(2), f(3), and f(4). [5
marks]
(b) Write a recursive Java function int f(int n) that implements
the above
definition. [10 marks]
(c) When calculating f(4), how many times is f called? Do not
count the initial
call to f(4) in your answer. Remember to show your working. [5
marks]
3. A function f takes an integer argument n and returns an integer. • If n < 2, the value of f(n) is n + 1. • If n > 2,
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
3. A function f takes an integer argument n and returns an integer. • If n < 2, the value of f(n) is n + 1. • If n > 2,
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!