Heap's Algorithm
4 min readFeb 21, 2021
Find All the Permutations of a Set of Elements
A classic technical interview question is finding the permutations of characters in a string. This string problem is a subset of the challenge of finding all the permutations of elements in a set. One of the most common algorithms to tackle this problem is Heap's Algorithm. Heap's is a relatively young algorithm first proposed by B. R. Heap in 1963.
I've laid out the algorithm's pseudocode with an explanation below:
PROCEDURE HEAP(S,N)
IF n == 1 THEN
process S
ELSE
FOR i := 0 TO n - 1…