You have no terminating condition for your recursion, so it runs forever.
It sounds like maybe you don't have a good grasp of recursion, so I'd like to start with something a little simpler, the Fibonacci sequence.
Any time we define a function in terms of recursion, we need to first define a base case(s). In the case of Fibonacci, we have 2 base cases:
F(0) = 0
F(1) = 1
That says, in english, "F of 0 is 0, F of 1 is 1". Or even more simply, if we pass 0 to function F, we will get 0 back. If we pass 1, we will get 1 back.
Once we have the base cases defined, then we need to look for a recurrence relation. In the case of Fibonacci, we have the following recurrence:
F(n) = F(n-1) + F(n-2)
So for n >= 2, we can use the above recurrence. Why? Well, lets try it for n = 2.
F(2) = F(n-1) + F(n-2)
= F(1) + F(0)
= 1 + 0
= 1
So now we know that the answer to F(2) is 1. And what's more, we can now compute the answer to F(3). Why? Well, what do we need to compute F(3)? We need F(2) and F(1). We now have both of those answers since F(1) is a base case, and we just solved F(2) above.
So, now let's try to write a piece of pseudo code to solve F.
function F(int n) {
// handle base cases
if (n equals 0)
return 0
if (n equals 1)
return 1
// recurrence
return F(n-1) + F(n-2);
}
Note that in a recursive function, we always handle the base cases at the beginning of the function. We cannot define this recurrence if we don't have base cases in place, otherwise, we will have no terminating condition for our recurrence. So that's why you always put the base cases at the beginning of the function.
Now, given the above explanation, another good exercise would be to write a recursive function for the factorial function. So, follow these steps:
1. Define the base case (use wikipedia article for hints).
2. Define recurrence in terms of base case
3. Write pseudo code to solve the recurrence, and be sure to put base case(s) at beginning of function, and recurrence at end.
Once you grasp these steps, then moving on to the power recurrence should make much more sense to you.