Step 1: Start with index 0, swap element at 0 with 0 (no change), recurse to index 1
[1, 2, 3]
Why: Fix first element and generate permutations of the rest
Step 2: At index 1, swap element at 1 with 1 (no change), recurse to index 2
[1, 2, 3]
Why: Fix second element and generate permutations of the rest
Step 3: At index 2, reached end, record permutation [1, 2, 3]
[1, 2, 3]
Why: One complete permutation found
Step 4: Backtrack to index 1, swap element at 1 with 2, array becomes [1, 3, 2], recurse to index 2
[1, 3, 2]
Why: Try next element at position 1
Step 5: At index 2, reached end, record permutation [1, 3, 2]
[1, 3, 2]
Why: Another complete permutation found
Step 6: Backtrack to index 0, swap element at 0 with 1, array becomes [2, 1, 3], recurse to index 1
[2, 1, 3]
Why: Change first element to next option
Step 7: At index 1, swap element at 1 with 1 (no change), recurse to index 2
[2, 1, 3]
Why: Fix second element and generate permutations of the rest
Step 8: At index 2, reached end, record permutation [2, 1, 3]
[2, 1, 3]
Why: Complete permutation found
Result: [1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 2, 1]
[3, 1, 2]