Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Input: f(2)
- f(x=2,n=1):
- x>0 = True, thus do a recursive call:
- f(2 - 1/1, 2)+1
- f(x=1,n=2)
- x>0 = True, thus do a recursive call:
- f(1 - 1/2, 3)+1
- f(x=0.5,n=3)
- x>0 = True, thus do a recursive call:
- f(0.5 - 1/3, 4)+1
- f(x=0.1666...,n=4)
- x>0 = True, thus do a recursive call:
- f(0.166... - 1/4, 5)+1
- f(-0.08333...,n=5)
- x>0 = False
- Now the caller goes back:
- f(-0.08333...,n=5) = False, so:
- f(0.166... - 1/4, 5)+1 becomes 1 (False implicitly becomes 0, which becomes 1 when adding 1)
- f(x=0.1666...,n=4) = 1, so:
- f(0.5 - 1/3, 4)+1 becomes 2
- f(x=0.5,n=3) = 2, so
- f(1 - 1/2, 3)+1 becomes 3
- f(x=1,n=2) = 3, so
- f(2 - 1/1, 2)+1 becomes 4
- f(x=2,n=1) is therefore 4
- So our result for f(2) = 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement