mathematics behind patience sorting david barra capstone advisor: dr. king

23
Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Upload: erick-harper

Post on 12-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Mathematics Behind Patience Sorting

David BarraCapstone Advisor: Dr. King

Page 2: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

What is Patience Sorting?

Simple one person card game that is a practical method of sorting a real deck of cards

Take a deck of cards labeled 1, 2, 3, …, n. The deck is shuffled and cards are turned up one at a time and dealt into piles on the table.

At each stage of the game, we see the top card of each pile.

A low card may be placed on a higher card, or may be put into a new pile to the right of the existing pile.

The object of the game is to finish with as few piles as possible.

Page 3: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Example of Patience Sorting

Permutation {8 3 7 9 2 5 4 1 10 6}

Page 4: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Patience Sorting Mathematics

Random set of n cards can be represented by a permutation of n elements

An example for n = 10 is {8 3 7 9 2 5 4 1 10 6}

The optimal way to play patience sorting is to play using the Greedy Algorithm

The greedy algorithm says to always take the best move at that given time. It involves no look ahead strategy.

The greedy strategy is to always place a card on the leftmost possible pile, thus taking advantage of the first opportunity to place a card on top of another.

Page 5: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Patience Sorting Mathematics

When patience sorting is played using the Greedy strategy, the game will finish with (ℓ π) piles where (ℓ π) is the length of the longest increasing

scattered subsequence of a permutation π. The longest increasing scattered subsequence is

the longest subsequence of increasing terms, where intervening, non-increasing terms may be dropped.

Example π = {8 3 7 9 2 5 4 1 10 6}. Longest increasing scattered subsequence is {3

7 9 10} ℓ(π) = 4

Page 6: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Lemma 1

With deck π, patience sorting played using the greedy strategy ends with ℓ(π) piles. Furthermore, the game played with any legal strategy will end with at least ℓ(π) piles. Therefore, the greedy strategy is the optimal way to patience sort.

Page 7: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Proof: First we show that the number of piles is at least (ℓ π).

If a subsequence of cards a1 < a2 < a3 < … < an

appears in increasing order in a permutation of cards π, then under any legal strategy, each ai must be placed in some pile to the right of ai-1, because the top card of each pile can only decrease. In other words, no two cards in any increasing subsequence may end up in the same pile. Therefore, the final number of piles is at least the length of any increasing subsequence of π, and therefore, at least (ℓ π).

Page 8: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Proof (cont.): Next we show that the number of piles is at most (ℓ π).

We can use patience sorting to find an instance of an increasing subsequence thereby showing that we have at most (ℓ π) piles.

Every time we place a card c in a pile i that is not the first pile, draw an arrow from c to the top card d of the previous pile. We know d<c and each arrow goes from a later card to an earlier card.

The path of the arrows represents an increasing sequence in π.

Therefore, the number of piles is at most (ℓ π).

Since the number of piles is also at least (ℓ π), the number of piles is (ℓ π).

Page 9: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Playing with a 52 card deck To play with a deck of 52 cards, we need to linearly order

the fifty cards. The problem with 52 cards is that you may find yourself in

the situation where, for example, a 3 is the top card of a pile and you are holding a 3. You need to know whether or not you can place that 3 on top of the other one. There can’t be any ties in patience sorting.

To solve the problem, order the suits. This orders the 52 cards such that you could order them 1, 2, 3,…, 52 in increasing order.

1 2 3 4 5 6 7 8 9 10….

Page 10: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Objective

Compute the probability distribution of (ℓ π) for permutations of a given length n. In other words, what is the probability of getting (ℓ π) = 1, 2, 3,…, n for a permutation of length n? Three methods we investigate are:

Patience Sorting with every possible permutation of length n

Formula formed from the Schensted Correspondence Mapping between a permutation and the

combinatorical structures called standard Young tableaux

Maple Programming

Page 11: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Compute P(Ln= ) by Patience SortingℓExample for permutation of

length 3π # Piles

{1, 2, 3} 3

{1, 3, 2} 2

{2, 1, 3} 2

{2, 3, 1} 2

{3, 1, 2} 2

{3, 2, 1} 1

Probability Distribution is:

• P(L3 = 1) = 1 / 6

• P(L3 = 2) = 4 / 6

• P(L3 = 3) = 1 / 6

Page 12: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Standard Young Tableaux Along each row and down each column, we place the numbers

1…n in the cells in increasing order. This gives rise to a partition of a number n putting it in a standard Young tableau of shape λ, size n.

The size n of a standard Young tableau is the number of cells it contains.

Partition λ is the shape of the standard Young tableau of size n. A partition λ = (λ1, λ2,…, λj) of an integer n ≥ 1 is a sequence with λ1 ≤ λ2 ≤ … ≤ λj, where λi is the number of cells in row i.

dλ is the number of standard Young tableaux of a given shape

Page 13: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Standard Young Tableaux

The idea is to construct a pair of standard Young tableau from a permutation π by using the Schensted Column Insertion Algorithm. This forms a bijection between permutations and pairs of standard Young tableaux (P,Q). This is the Schensted Correspondence.

For π = {8 3 7 9 2 5 4 1 10 6}

1 4 6 10

2 5 9

3

7

8

P Tableau

Q Tableau

1 3 4 9

2 610

5

7

8

Page 14: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

How to construct P tableau from permutation π

π = {8 3 7 9 2 5 4 1 10 6}

1. Place card into top row of tableau by patience sorting

2. If a card is covered, place it into the next row by patience sorting (thus bumping it)

Page 15: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

P tableau for π = {8 3 7 9 2 5 4 1 10 6}

Page 16: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Correspondence between Permutations of π cards and pairs of Standard Young Tableaux The length of the top

row in the Young tableau associated with a permutation π is the length of the longest increasing scattered subsequence of π.

Furthermore, the top row is the same as the top card of each pile in patience sorting.

This is another way to calculate (ℓ π)

P Tableau for

π = {8 3 7 9 2 5 4 1 10

6}. Longest increasing

subsequence is {3 7 9

10}

1 4 6 10

2 5 9

3

7

8

Page 17: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

How does everything relate to each other?

π P tableau Q tableauLength of top row of tableaux

Patient Sort

# Piles

ℓ(π)

{1, 2, 3} 3 3 3

{1, 3, 2} 2 2 2

{2, 1, 3} 2 2 2

{2, 3, 1} 2 2 2

{3, 1, 2} 2 2 2

{3, 2, 1} 1 1 1

2

31

2

31

2

31

2

31

2

31

2

31

2

31

2

31

3

21

3

21

3

21

3

21

3

21

3

21

3

21

3

21

321 321 321 321

3

2

1

3

2

1

3

2

1

3

2

1

Page 18: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Correspondence between permutation of π cards and pairs of standard Young tableaux This gives a formula

for the probability P(Ln= ) that the ℓlongest increasing scattered subsequence of a random permutation of {1, 2, …, n) has length .ℓ

Page 19: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Applying the Formula for P(L3= ) ℓ

P(L3 = 1) = (1 / 3!) ∙ 12 = 1 / 6

P(L3 = 2) = (1 / 3!) ∙ 22 = 4 / 6

P(L3 = 3) = (1 / 3!) ∙ 12 = 1 / 6

d(3) = 1

d(2,1) = 2

d(1,1,1) = 1

1 2 3

1 2 1 3

3 2

3

2

1

Remember: dλ is the number of standard Young tableaux of a given shape

Page 20: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Programming Maple to Patience SortBy David Barra and Dr. Wyels

Program Maple to Patience Sort using patience sorting as the algorithm for computing (ℓ π)

Program Maple to collect the data for a large number of trials and find the P(Ln= ) for a given ℓn

Page 21: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Acknowledgements

Dr. King Dr. Fogel Dr. Wyels David Parker Lucas Lembrick

Page 22: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

Sources

Diaconis, Perci. “Longest Increasing Subsequences: From Patience Sorting to the Baik-Deift-Johansson Theorem.” Stanford University, 1999.

D. Stanton and D. White. Constructive Combinatorics. Undergraduate Textbooks in Mathematics. Springer and Verlag, 1986.

Eric. W Weisstein. “Young Tableau.” From Mathworld—A Wolfram Web Resource. http://mathworld.wolfram.com/Youngtableau.html

Page 23: Mathematics Behind Patience Sorting David Barra Capstone Advisor: Dr. King

The Hook Formula (another way to calculate dλ)

The hook length of a cell hc is the number of cells in the set consisting of the cells to the right of c in its row, the cells below c in its column, and c itself.

The number of standard Young tableau dλ of a given shape λ, is given by the Hook Formula.

dλ = n! / (Πc hc)