Skip to content

Commit

Permalink
📚 docs(_fisheryates): Add references.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Apr 6, 2021
1 parent 0dd55b3 commit 21c8bdd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/kernel/_fisheryates.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
/**
* Sample array using Fisher-Yates method.
* Sample element from an array using Fisher-Yates method.
*
* NOTE: The original description of the algorithm by Fisher and Yates [1] had
* unnecessary bookkeeping which made the algorithm run in O(n * (j-i)) time.
* This implementation follows Durstenfeld's [2] and Knuth's [3] descriptions
* which yield O(n) running time.
*
* For more information see the excellent "Fisher–Yates shuffle" page on
* Wikipedia [4]. Fisher and Yates description is referred there as
* "Fisher and Yate's original method" or "pencil-and-paper method".
* The more efficient implementation described by Durstenfeld and Knuth is
* referred there as "the modern method".
*
* [1] Fisher, Ronald A.; Yates, Frank (1938). Statistical tables for
* biological, agricultural and medical research.
* [2] Durstenfeld, R. (July 1964). "Algorithm 235: Random permutation"
* [3] Knuth, Donald E. (1969). Seminumerical algorithms. The Art of Computer
* Programming Volume 2.
* [4] https://en.wikipedia.org/wiki/Fisher–Yates_shuffle
*/

const _fisheryates = (randint) => (n, a, i, j) => {
// We will swap at most n elements
// NOTE: When n = j - i, the last swap swaps a[j-1] with itself,
Expand Down

0 comments on commit 21c8bdd

Please sign in to comment.