Recursive definition with several things wrong

37 Views Asked by At

There are several things wrong with the following recursive definition. The function is meant to be valid for all nonnegative integers. Provide me with 3 errors in the following recursive function:

$ f(a,b) = \left\{ \begin{array}{l l} 1 & \quad \text{if $b = 0$}\\ 1 & \quad \text{if $b = 1$}\\ 1 & \quad \text{if $b = 2$}\\ f(b-1, b) & \quad \text{if $20 \ge b \ge 2$} \\ f(b-4, b-1) & \quad \text{if $b \ge 20$} \end{array} \right. $

I have come up with four possible errors so far however I am not sure if I am correct

  1. I am not really sure if this counts as an error but $a$ in this function is irrelevant, it doesn't add anything to the function

  2. when $20 \geq b \geq 2$ = $f(b-1,b)$ $b$ doesn't get incremented or decremented by anything. If you were to write a recursive function in java it would throw a stack overflow error instantly. If you were to change it to $b - 1$ it will work but you will always get one for your answer.

  3. Bad base cases for $b = 0 - 2$ as you will only be able to get one as an answer.

  4. when $20 \geq b \geq 2$ the $b \geq 2$ is irreverent because there is already a base case for b = 2

If anyone sees anything else worth noticing or I am wrong about one of my possible errors. Please let me know I am just trying to see the bigger picture here.