Going by the if
statements:
fib(0) = 0
fib(1) = 1
fib(2) = fib(2-1) + fib(2-2)
= fib(1) + fib(0)
= 1 + 0
= 1
fib(3) = fib(3-1) + fib(3-2)
= fib(2) + fib(1)
= fib(2-1) + fib(2-2) + 1
= fib(1) + fib(0) + 1
= 1 + 0 + 1
= 2
fib(4) = fib(4-1) + fib(4-2)
= fib(3) + fib(2)
= fib(3-1) + fib(3-2) + fib(2-1) + fib(2-2)
= fib(2) + fib(1) + fib(1) + fib(0)
= fib(2-1) + fib(2-2) + 1 + 1 + 0
= fib(1) + fib(0) + 1 + 1 + 0
= 1 + 0 + 1 + 1 + 0
= 3
solved Could someone explain this recursive function? [closed]