Permutations
Swap each remaining element into the next position, recurse, and swap back; n! leaves.
Decision · step 2 of 32Enumeration: All orderings of three
Position 0: keep 1 where it is and fix it. Recurse on positions 1 onward.
What you will see
The tree fans out by remaining choices; a used-set blocks repeats.
Cost
| Best | O(n * n!) |
|---|---|
| Average | O(n * n!) |
| Worst | O(n * n!) |
| Space | O(n) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Each node of the decision tree announces the choice made and whether it led to success, failure or further choices.
Reduced motion: Tree nodes appear and grey out in place; no travelling focus.
Before this
Taught by the same lesson
Enumeration covers these too, in the same run.