Advertisement
Guest User

Untitled

a guest
Feb 10th, 2020
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. Input: f(2)
  2.  
  3. f(x=2,n=1):
  4. x>0 = True, thus do a recursive call:
  5. f(2 - 1/1, 2)+1
  6. f(x=1,n=2)
  7. x>0 = True, thus do a recursive call:
  8. f(1 - 1/2, 3)+1
  9. f(x=0.5,n=3)
  10. x>0 = True, thus do a recursive call:
  11. f(0.5 - 1/3, 4)+1
  12. f(x=0.1666...,n=4)
  13. x>0 = True, thus do a recursive call:
  14. f(0.166... - 1/4, 5)+1
  15. f(-0.08333...,n=5)
  16. x>0 = False
  17.  
  18. Now the caller goes back:
  19. f(-0.08333...,n=5) = False, so:
  20. f(0.166... - 1/4, 5)+1 becomes 1 (False implicitly becomes 0, which becomes 1 when adding 1)
  21. f(x=0.1666...,n=4) = 1, so:
  22. f(0.5 - 1/3, 4)+1 becomes 2
  23. f(x=0.5,n=3) = 2, so
  24. f(1 - 1/2, 3)+1 becomes 3
  25. f(x=1,n=2) = 3, so
  26. f(2 - 1/1, 2)+1 becomes 4
  27. f(x=2,n=1) is therefore 4
  28.  
  29. So our result for f(2) = 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement