Step 1: Start with index 0, swap element at index 0 with itself
[1, 2, 3]
Why: Begin permutations by fixing the first element as 1.
Step 2: Move to index 1, swap element at index 1 with itself
[1, 2, 3]
Why: Fix second element as 2, continue to permute the rest.
Step 3: Move to index 2, swap element at index 2 with itself, record permutation
[1, 2, 3]
Why: Reached end, record current order as a valid permutation.
Step 4: Backtrack to index 1, swap element at index 1 with element at index 2
[1, 3, 2]
Why: Try new order by swapping second and third elements.
Step 5: Move to index 2, swap element at index 2 with itself, record permutation
[1, 3, 2]
Why: Reached end again, record this new permutation.
Step 6: Backtrack to index 0, swap element at index 0 with element at index 1
[2, 1, 3]
Why: Change first element to 2, explore permutations starting with 2.
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 with first element fixed as 2.
Step 8: Backtrack to index 0, swap element at index 0 with element at index 2
[3, 2, 1]
Why: Change first element to 3, explore permutations starting with 3.
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 with first element fixed as 3.
Result: All permutations:
[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 2, 1]
[3, 1, 2]