A. The list current is not restored after adding elements, causing incorrect subsets
B. The base case condition is wrong
C. The function should return a value
D. The index variable is not incremented
Solution
Step 1: Analyze list modification
After adding element to current, it is not removed before backtracking, so subsets accumulate extra elements.
Step 2: Identify fix
Need to remove last added element after recursive call to restore state.
Final Answer:
The list current is not restored after adding elements, causing incorrect subsets -> Option A
Quick Check:
Backtracking requires undoing changes [OK]
Hint: Always undo list changes after recursive calls [OK]
Common Mistakes:
Forgetting to remove added elements after recursion
Misunderstanding base case
Expecting return value from void method
5. You want to use backtracking to find all ways to climb a staircase of 4 steps, taking either 1 or 2 steps at a time. Which decision tree correctly represents the choices at each step?
medium
A. Root at step 0, branches to step 1 and step 2, each branch continues similarly until step 4
B. Root at step 4, branches to step 3 and step 2, moving backward
C. Root at step 0, branches only to step 1 repeatedly until step 4
D. Root at step 1, branches to step 3 and step 4 directly
Solution
Step 1: Understand problem steps
Starting at step 0, choices are to move 1 or 2 steps forward until reaching step 4.
Step 2: Match decision tree structure
Root at step 0, branches to step 1 and step 2, each branch continues similarly until step 4 shows root at 0 with branches to 1 and 2, continuing until 4, matching the problem.
Final Answer:
Root at step 0, branches to step 1 and step 2, each branch continues similarly until step 4 -> Option A
Quick Check:
Decision tree = choices from start to goal [OK]
Hint: Decision tree starts at initial state, branches by choices [OK]
Common Mistakes:
Starting decision tree at goal instead of start
Ignoring possible step sizes
Skipping intermediate steps in tree
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.