
confused base case(s)
I understand that each recusive function must have one base case(A solution given directly) however they may also have two. This is where I get confused see below. Is my thinking below correct or way off?
Code:
int funct1(int m, int n) {
if (m==n  n==1) // single base case
return 1;
else
return funct1(m1,n1) + n*func1(m1, n);
}
if I broke these in two parts as below I would have two base cases. I think it still says the same as (this or that) Am I on the right track.
Code:
int ...................
if (m==n)
return 1 //1st base case
else if (n==1)
return 1 // 2nd base case
else
.........................

Logically your two constructs are exactly the same.
A recursive function must have at least one return to break the recursion, it can have any number >= 1.

Thanks,
I thought they were saying the same thing. To have two base cases one of the returns would have to be something other than 1?

I don't think it matters whether you write it as:
Code:
if (m==n  n==1)
return 1;
Or: Code:
if (m==n)
return 1; //1st base case
else if (n==1)
return 1; // 2nd base case
It's still two base cases. With the first example, you just combined the two base cases into one statement. Someone correct me if I'm wrong.

>To have two base cases one of the returns would have to be something other than 1?
one case may be 1, two or more cases may be 1, but no cases need to be 1, and in fact the case to stop it doesn't even have to be an int. You could stop it if the user enters a 'q' or types in quit or pushes the Page Up key, or presses the CtrAltDelete keys in combination. You just need something to stop it.