Computer Science: An Overview: Global Edition (12th Edition)

Published by Pearson Higher Education
ISBN 10: 1292061162
ISBN 13: 978-1-29206-116-0

Chapter 5 - Algorithms - Chapter Review Problems - Page 266: 35

Answer

2 0 1 -1

Work Step by Step

--- Call MysteryPrint(2) N > 0 → True Prints 2 Calls MysteryPrint(0) --- Call MysteryPrint(0) N > 0 → False, so go to else Prints 0 Check if (N > -1) → 0 > -1 → True Calls MysteryPrint(1) ---- Call MysteryPrint(1) N > 0 → True Prints 1 Calls MysteryPrint(-1) --- Call MysteryPrint(-1) N > 0 → False, so go to else Prints -1 Check if (N > -1) → -1 > -1 → False So no further recursive call, recursion ends here. Now we unwind back up (no more recursion calls left) No more print statements after recursion, so the full print sequence is: 2, 0, 1, -1
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.