midBacktracking
How do you generate all permutations of an array?
Updated Apr 28, 2026
Short answer
Use backtracking with visited tracking.
Deep explanation
At each step, pick an unused element and recurse until all elements are used.
Real-world example
Generating all orderings of tasks.
Common mistakes
- Not using visited array.
Follow-up questions
- Complexity?
- Why visited?