Overview
Heap's Algorithm enumerates all permutations of a list using a recursive swap pattern that changes one or two positions between generated permutations.
Generates permutations by recursively swapping elements.
Compact metadata for implementation and discovery.
Heap's Algorithm enumerates all permutations of a list using a recursive swap pattern that changes one or two positions between generated permutations.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n!) generated permutations
Average
O(n!) generated permutations
Worst
O(n!) generated permutations
Space
O(n) recursion depth plus output storage if materialized
Show recursive swap positions and the stream of generated permutations.
Heap's Algorithm is a deterministic permutation generator; procedural-generation is the closest current Atlas category because no combinatorial-generation category exists.
What each reference supports for this entry.
Supports Heap's permutation-generation method by interchanges and the one-swap transition mechanism between generated permutations.
Open sourceSurveys permutation-generation methods and supports Heap's Algorithm as a standard permutation-enumeration method.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Heap's Algorithm and Steinhaus-Johnson-Trotter are alternative deterministic permutation-generation methods.