Permutations
Choose one unused value per depth, record complete arrangements, and undo choices while exploring the decision tree.
Core idea
Fill one output position at a time by choosing any unused input value. A boolean used set enforces uniqueness, and backtracking releases each value for sibling branches.
Read the visualization
The decision tree has one level per output position. Descending edges add a value, leaf nodes record complete arrangements, and returning upward removes the final choice.
Start at the empty arrangement with every input value available.
Complexity and tradeoffs
Time: O(n × n!). Space: O(n). There are n! outputs, and writing each arrangement requires O(n) work.
Where it fits
Permutation search appears in small assignment, ordering, and route problems. Duplicate input values require sorting plus a same-depth skip rule to avoid repeated outputs.