1 / 23

Mathematics Behind Patience Sorting

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

stefanie
Download Presentation

Mathematics Behind Patience Sorting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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.

  3. Example of Patience Sorting • Permutation {8 3 7 9 2 5 4 1 10 6}

  4. 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.

  5. 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

  6. 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.

  7. 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 ℓ(π).

  8. 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 ℓ(π).

  9. 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….

  10. 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

  11. Compute P(Ln= ℓ) by Patience Sorting Example for permutation of length 3 • Probability Distribution is: • P(L3 = 1) = 1 / 6 • P(L3 = 2) = 4 / 6 • P(L3 = 3) = 1 / 6

  12. 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

  13. 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} P Tableau Q Tableau

  14. How to construct P tableau from permutation π • π = {8 3 7 9 2 5 4 1 10 6} • Place card into top row of tableau by patience sorting • If a card is covered, place it into the next row by patience sorting (thus bumping it)

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

  16. 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}

  17. How does everything relate to each other?

  18. 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 ℓ.

  19. 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 Remember: dλis the number of standard Young tableaux of a given shape

  20. 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

  21. Acknowledgements • Dr. King • Dr. Fogel • Dr. Wyels • David Parker • Lucas Lembrick

  22. 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

  23. 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)

More Related