# 随机算法 (Fall 2011)/Card Shuffling

# Riffle Shuffle

The following is the Gilbert-Shannon-Reeds model of riffle shuffle introduced by Gilbert and Shannon in 1955 and independently by Reeds in 1985.

**Riffle Shuffle (Gilbert-Shannon 1955; Reeds 1985)**- Given a deck of cards, at each round, do as follows.

- Split the original deck into two decks according to the binomial distribution .
- Cut off the first cards with probability , put into the left deck, and put the rest cards into the right deck.

- Drop cards in sequence, where the next card comes from one of the two decks with probability proportional to the size of the deck at that time.
- Suppose at a step there are cards in the left deck and cards in the right deck. A card is dropped from left with probability , and from right otherwise.

The second step actually samples a uniform interleaving of left and right deck. The magician and mathematician Diaconis in 1988 found evidence showing that this mathematical model reasonably approximate the riffle shuffling acted by human.

The above model is equivalent to the following model of inverse riffle shuffle.

**Inverse Riffle Shuffle**- Label each card with a bit from uniformly and independently at random.
- Place all cards labeled with 0 above all cards labeled with 1, keeping the cards with the same label in the same the relative order as before.

The process of inverse riffle shuffle is depicted as follows.

For each card, the random bits used for labeling the card compose a binary code , with the -th bit (from lower to higher radix) being the random bit chosen in round to label the card.

**Lemma**- After every round of the inverse riffle shuffle, the cards are sorted in non-decreasing order of their corresponding binary codes.

**Proof.**By induction. After the first round, all are above all s. Assume that the hypothesis is true for the first rounds. After the -th round, all cards with the highest coordinate are above all cards with , and by the definition of inverse riffle shuffle, cards with the same highest bit are kept in the same relative order as they are after the -th round of the shuffling, which due to the hypothesis, means that the cards with the same highest bit are sorted in the non-decreasing order of . By the definition of binary representation, all cards are sorted.

# Rapid Mixing of Riffle Shuffle by Coupling

**Theorem**- The mixing time of inverse riffle shuffle of a deck of cards is .

Consider two instance of shuffling, started with two decks, each in an arbitrary order. We couple the two shuffling processes by coupling their random choices of labelings:

- In each round, we label the same cards (same content, not the same order) in the two decks with the same random bit.

Formally, for each , we uniformly and independently choose a random as the label of the card in each of the two decks in that round. It is easy to see that, each of the two shuffling processes viewed individually follows exactly the rules of inverse riffle shuffle.

**Lemma**- With the above coupling rule, started with arbitrary two decks of cards, the two decks are the same once all cards in the first (or the second) deck have distinct labels.

**Proof.**By the definition of the coupling rule, any two identical cards in the two decks always have the same label, since in every round they choose the same random bit. And we have shown that after each round, the labels are sorted in non-decreasing order. Thus, we can conclude:

- after each round, the sequences of the labels of the two decks are identical (and sorted in non-decreasing order).

Therefore, when all cards in the first deck have distinct labels, the second deck have the same set of distinct labels, and the cards are sorted increasingly in their labels in the respective decks. Since any two identical cards have the same labels, the cards in the two decks must be in the same order.

We denote by the random variable representing the time that in an inverse riffle shuffle, all cards in the deck have distinct labels. Due to the coupling lemma for Markov chains,

- .

This bound can be deduced from the birthday problem. After round, each of the cards is randomly assigned one of the possible labels. We know that for some , i.e. , the probability that no two cards have the same label is , i.e. , thus

- .

Note that the state space is the set of all permutations, which is of size , whose logarithm is still as large as due to Stirling's approximation. Thus the riffle shuffle is mixing extremely fast.

This estimation of mixing time is fairly tight. For the case that , the real mixing rate is as follows.

1 2 3 4 5 6 7 8 9 1.000 1.000 1.000 1.000 0.924 0.614 0.334 0.167 0.003