Alice and Bob want to make a card shuffling machine for their poker club. The problem is that they propose different algorithms and thus can't decide which one to apply:
Whose algorithm is better, or does it really matter?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The answer might be counter-intuitive at first. Why is Bob's algorithm bad? Couldn't it generate all permutations? The answer is yes; it could generate all permutations, but not evenly. There is a total of n n moves, but there are only n ! permutations. Since n ! doesn't divide n n in general, not all permutations have equal chance to be generated.
Now we are convinced that Bob's algorithm is bad, but how bad it is? Noticed that if a card is swapped to its left, it couldn't go left any further!
Still not convinced? Let the data do the speaking.
The left image is Alice's algorithm and the right one is Bob's. The x-axis is the numbers, and the y-axis is the position it ended up after going through the algorithm. The brighter the cell, the higher frequency the number ended up in that position. As you can see, most of the numbers ended up being on its left!
If you are interested in how the visualisation is generated, here is the code: