🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.To print the string in reverse
  2. B.To restore the string so the next choice starts from the original order
  3. C.To free memory
  4. 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 →