Step 1: Start with index 0, swap element at 0 with 0 (no change)
[1, 2, 3]
Why: Fix first element and permute the rest
Step 2: Move to index 1, swap element at 1 with 1 (no change)
[1, 2, 3]
Why: Fix second element and permute the rest
Step 3: Move to index 2, swap element at 2 with 2 (no change), record permutation
[1, 2, 3]
Why: Reached end, record current order
Step 4: Backtrack to index 1, swap element at 1 with 2
[1, 3, 2]
Why: Try next possible element at position 1
Step 5: Move to index 2, swap element at 2 with 2 (no change), record permutation
[1, 3, 2]
Why: Reached end, record current order
Step 6: Backtrack to index 0, swap element at 0 with 1
[2, 1, 3]
Why: Try next possible element at position 0
Step 7: Repeat steps for index 1 and 2 to generate permutations starting with 2
[2, 1, 3] then [2, 3, 1]
Why: Generate all permutations starting with 2
Step 8: Backtrack to index 0, swap element at 0 with 2
[3, 2, 1]
Why: Try next possible element at position 0
Step 9: Repeat steps for index 1 and 2 to generate permutations starting with 3
[3, 2, 1] then [3, 1, 2]
Why: Generate all permutations starting with 3
Result: All permutations:
[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 1, 2]
[3, 2, 1]