Content deleted Content added
No edit summary Tag: gettingstarted edit |
|||
Line 1:
{{Copy edit|date=December 2013}}
'''Heap's algorithm''' is an [[algorithm]] used for generating [[permutation]]s. It was first proposed by B. R. Heap in 1963.<ref>{{cite journal|last=Heap|first=B. R.|title=Permutations by Interchanges|journal=The Computer Journal|year=1963|volume=6|issue=3|pages=293–4|url=http://comjnl.oxfordjournals.org/content/6/3/293.full.pdf}}</ref> It interchanges the positions of elements to generate the next permutation. In a 1977 review of permutation-generating algorithms, [[Robert Sedgewick (computer scientist)|Robert Sedgewick]] concluded that it was the most effective algorithm for Heap's algorithm is an algorithm used for generating permutations. It was first proposed by B. R. Heap in 1963.[1] It interchangHeap's algorithm is an algorithm used for generating permutations. It was first proposed by B. R. Heap in 1963.[1] It interchanges the positions of elements to generate the next permutation. In a 1977 review of permutation-generating algorithms, Robert Sedgewick concluded that it was the most effective algorithm for then-current computerses the positions of elements to generate the next permutation. In a 1977 review of permutation-generating algorithms, Robert Sedgewick concluded that it was the most effective algorithm for then-current computersthen-current computers.<ref>{{cite doi|10.1145/356689.356692}}</ref>Heap's algorithm is an algorithm used for generating permutations. It was first proposed by B. R. Heap in 1963.[1] It interchanges the positions of elements to generate the next permutation. In a 1977 review of permutation-generating algorithms, Robert Sedgewick concluded that iHeap's algorithm is an algorithm used for generating permutations. It was first proposed by B. R. Heap in 1963.[1] It interchanges the positions of elements to generate the next permutation. In a 1977 review of permutation-generating algorithms, Robert Sedgewick concluded that it was the most effective algorithm for then-current computerst was the most effective algorithm for then-current computers
Heap's algorithm is an algorithm used for generating permutations. It was first proposed by B. R. Heap in 1963.[1] It interchanges the positions of elements to generate the next permutation. In a 1977 review of permutation-generating algorithms, Robert Sedgewick concluded that it was the most effective algorithm for then-current computers
== Details of the algorithm ==Heap's algorithm is an algorithm used for generating permutations. It was first proposed by B. R. Heap in 1963.[1] It interchanges the positions of elements to generate the next permutationHeap's algorithm is an algorithm used for generating permutations. It was first proposed by B. R. Heap in 1963.[1] It interchanges tHeap's algorithm is an algorithm used for generating permutations. It was first proposed by B. R. Heap in 1963.[1] It interchanges the positions of elements to generate the next permutation. In a 1977 review of permutation-generating algorithms, Robert Sedgewick concluded that it was the most effective algorithm for then-current computershe positions of elements to generate the next permutation. In a 1977 review of permutation-generating algorithms, Robert Sedgewick concluded that it was the most effective algorithm for then-current computers. In a 1977 review of permutation-generating algorithms, Robert Sedgewick concluded that it was the most effective algorithm for then-current computers
Suppose we have a sequence of different characters with a length of ''N''. Heap found that we can interchange the positions of two elements to get a new permutation output. Let us describe it in a recursive way. If we have got (''N'' − 1)<nowiki>!</nowiki> permutation outputs, fixing the last element. Then if ''N'' is odd, we can switch the first element and the last one, while ''N'' is even we can switch the ''i''th (''i'' is the step number of the cycle, and now it is 1) element and the last one, then we will continue outputting the (''N'' − 1)<nowiki>!</nowiki> permutation outputs and switching step for another ''N'' − 1 times(''N'' times int total). The following pseudocode outputs permutations of a data array of length ''N''.
|