← Quiz: Recursion and Stack Frames: all 10 questions
Quiz: Recursion and Stack Frames · Question 9 of 10
In the permutation program, why is the second swap ("undo") needed?
In the permutation program, why is the second swap ("undo") needed?
- A.To print the string in reverse
- B.To restore the string so the next choice starts from the original order
- C.To free memory
- D.It is not needed; it only makes the code slower
Answer & explanation
Correct answer: To restore the string so the next choice starts from the original order
Backtracking means undoing a choice after exploring it; without it, later branches start from a scrambled string.
Can you get the rest right without peeking?
Take the timed Quiz: Recursion and Stack Frames quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →