You might try to eyeball it, or go from it more systematically. Assuming we're doing this from scratch, we should try build a recurrence relation from the function definition.
We can assume, for the moment, a very simple machine model where arithmetic operations and variable lookups are constant time.
Let iter-cost
be the name of the function that counts how many steps it takes to compute iter
, and let it be a function of p
, since iter
's termination depends only on p
. Then you should be able to write expressions for iter-cost(0)
. Can you do that for iter-cost(1)
, iter-cost(2)
, iter-cost(3)
, and iter-cost(4)
?
More generally, given an p
greater than zero, can you express iter-cost(p)
? It will be in terms of constants and a recurrent call to iter-cost
. If you can express it as a recurrence, then you're in a better position to express it in a closed form.