So, I know how to trace an algorithm in discrete mathematics when you have e.g., a for or while loop and then output. But, for some unknown reason, I am lost when it comes to tracing a recursive function calling itself.
def func(n):
if n = 1 then:
func <- 3 + 6
else
func <- (-n) + 2 * func(n - 1)
trace table: func(5)
-------------------------------
| step | n | r | output |
-------------------------------
| 1. | 5 | - | - |
| 2. | 5 | 0 | - |
This question, is not concerned with counting, because I've done this already by paper and hand. I even written the method in Python, and received the same output.
def func(n):
r = 0;
if n == 1:
r = 3 + 5
else:
r = (-n) + 2 * func(n-1)
return r
print(func(1)) = 8
print(func(2)) = 14
print(func(3)) = 25
print(func(5)) = 87