Skip to content

Instantly share code, notes, and snippets.

View OahMada's full-sized avatar

Adam Hao OahMada

  • Mainland of China
View GitHub Profile

Heap's Algorithm step by step

Take the example of generating the permutations of the array ['a', 'b', 'c', 'd'].

Assume that the function named generate(n, arr) with two parameters: n is the length of the array; and the arr is the array to be dealt with.

And the calling statement would be: generate(4, ['a', 'b', 'c', 'd']);.

There's a for loop inside the algorithm. So: