October 2025
Intermediate to advanced
485 pages
13h 2m
English
Let’s analyze the efficiency of the Fisher-Yates Shuffle. The steps of this algorithm consist of generating random numbers and performing swaps. For each of the N values in the array (besides the last one), we generate a random number and then perform a swap. All in all, this is N-1 number generations, and N-1 swaps, yielding 2N-2 steps, which boils down to O(N). This is way faster than any known sorting algorithm, and kind of makes sense since it’s a lot easier to make chaos out of order than it is to make order out of chaos.
In terms of space, the Fisher-Yates Shuffle jumbles all the values in place and doesn’t consume any extra memory.
Now that we’ve determined that shuffling takes O(N) time, we ...
Read now
Unlock full access