Is this AP CSA Question Wrong?
Posted by Straight-Ad7648@reddit | programming | View on Reddit | 5 comments
I just randomly came across this. I'm looking at question 3, tracing the recursive algorithm.
No matter how I look at it, I cannot get one of the supplied answers. I don't see how any of the calls would output even a single 0
Anyone?
programming-ModTeam@reddit
This post was removed for violating the "/r/programming is not a support forum" rule. Please see the side-bar for details.
gHx4@reddit
I have encountered real exam questions about recursion that stack overflow, because recursion doesn't magically solve concerns like the memory used by stack frames. But this one will only execute 1 + 3! times, resulting in 7 characters output.
If you see typos like this, raise your hand and ask the proctor to flag the question as a potential typographical error. (C) is close if you treat the print as
System.out.print(i)(which I originally had while skimming the question. Otherwise, pulling the print out of the loop results in (D) being correct.gHx4@reddit
I have encountered real exam questions about recursion that stack overflow, because recursion doesn't magically solve concerns like the memory used by stack frames. But this one will only execute 1 + 3! times, resulting in 7 characters output. It is not a typo, you will never see a 3 in the question as written, and (C) is the correct answer.
fiskfisk@reddit
There is no value "returned by the call
mystery(n)". The method is definedvoid.That should tell you all about how exact this set of questions is.
You can just try to run the code and see what the output will be.
Hint: it's not any of the options.
They probably intended for the code to be:
This gives option D as the correct answer.
Straight-Ad7648@reddit (OP)
Yeah that's what I mean. The print statement being inside the loop means it can't possibly print any zeroes because a 0 will fail the loop condition. Also, the print being inside the loop makes the recursion tracing an absolute nightmare as you're unwinding loops WITHIN recursion on the call stack. I can't imagine they would need high school students to do this