# confused base case(s)

Printable View

• 06-29-2005
tgtgtg
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(m-1,n-1) + n*func1(m-1, 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                   .........................```
• 06-29-2005
mitakeet
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.
• 06-29-2005
tgtgtg
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?
• 06-29-2005
swoopy
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.
• 06-29-2005
elad
>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 Ctr-Alt-Delete keys in combination. You just need something to stop it.