Question:
Recursion C++ programing question? Me vs Professor?
Neph
2010-08-09 21:08:39 UTC
Before I go and argue with my professor can someone just see it me if I'm right or wrong?
On my quiz one of my questions was:

16. Suppose that a recursive function with integer parameter n has a base case of 0, and for each non-base case, the function makes a recursive call with argument n+1. If the function is initially called with an actual argument of n = 3, the function call will...

My answer was...
will cause an infinite chain of recursive calls.
If the recursive functions base case is 0
and the initial value is 3
and makes a recursive call with an argument n+1
the value of n on the next call will be 4 then 5 never reaching 0
therefore causing an infinite chain of recursive calls.

HE SAID...
No, it will return after a call of 3 recursive calls.

Can someone please clear this up for me, I'm going to talk to him about it Wednesday 9/11/10 . I just want to make sure I'm right about this before I confront him.

He will be sure to make me feel like an *** if I'm wrong and challenge him. So before I go through that again I just want to make sure I'm right. I got 19 out of 20 and this question was the one I got wrong.
Five answers:
Ratchetr
2010-08-09 21:23:38 UTC
You appear to be right. I can't see any way around it, unless there is more to this question than what you posted.



Prof probably meant to type n-1, and thinks (s)he did. They do make mistakes...although sometimes their ego prevents them from ever seeing it.



This has worked reasonably well for me in life: If you are certain you are right...double check and triple check yourself first. If you're still convinced you are right...go argue your case...and don't walk away until you win your case...or you're proven wrong. And if you are proven wrong...live with it. You learned something in the process.
leo
2010-08-10 04:17:08 UTC
I am not a programmer. But as no one answered so i am contributing. I think if a recursive call with an argument n-1, then it will make 3 iterations.



I think you should not argue with teacher, just try to convince him in a nice polite way. Or ask him to clear it to you that how the program will make three iterations...
Light Cloud
2010-08-10 04:40:58 UTC
You are right. I think perhaps the professor meant to say that the function makes a recursive call with argument n-1, and typo'd.
oops
2010-08-10 04:16:30 UTC
You are correct, except that it won't be infinite, it will go to INT_MAX, then INT_MIN, then it will count up to 0 and stop, if the stack doesn't overflow first, which it probably will.
Brian
2010-08-10 04:17:26 UTC
me and my friend both say your right..but then again we got a one the ap comp sci test =P


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...