![]() |
![]() |
|
![]() |
![]() |
Encyclopedia :
P :
PA :
PAT :
Patience sorting |
|
|
Patience sortingPatience sorting is a sorting algorithm, based on a solitaire card game, that has the property of being able to efficiently compute the length of the longest increasing subsequence in a given array.The card gameThe game begins with a shuffled deck of cards, labeled . (To play with a regular 52-card deck, some ordering needs to be imposed, arranging the cards within a suit and imposing some order on the suits). The cards are dealt one by one into sequence of piles on the table, according to the following rules. The object of the game is to finish with as few piles as possible. D. Aldous and P. Diaconis ([1], p.414) suggest defining 9 or less piles as a winning outcome for , which has approximately 5% chance to happen. Algorithm for sortingGiven an -element array with an ordering relation as an input for the sorting, consider it as a collection of cards, with the (unknown in the beginning) statistical ordering of each element serving as its index. Note that the game never uses the actual value of the card, except for comparison between two cards, and the relative ordering of any two array elements is known. Now simulate the patience sorting game, played with the greedy strategy, i.e., placing each new card on the leftmost pile that is legally possible to use. At each stage of the game, under this strategy, the labels on the top cards of the piles are increasing from left to right. To recover the sorted sequence, collect the minimum card from the top row each time. For a description of an efficient implementation with worst-case running time and space spent for supporting structures, relying on a van Emde Boas tree, please see the work by S. Bespamyatnikh and M. Segal ([4], pp.7–8). Algorithm for finding the longest increasing subsequenceFirst, execute the sorting algorithm as described above. The resulting number of piles will equal the length of the longest increasing subsequence. Whenever a card is placed on top of a pile, put a back-pointer to the top card in the previous pile (that, by assumption, has a lower value than the new card has). In the end, follow the back-pointers from the top card in the last pile to recover a decreasing subsequence of the longest length; its reverse is an answer to the longest increasing subsequence algorithm. S. Bespamyatnikh and M. Segal ([4], pp.3–5) give a description of an efficient implementation of the algorithm, incurring no additional asymptotic cost over the sorting one (as the back-pointers storage, creation and traversal require linear time and space). They further show how to report all the longest increasing subsequences from the same resulting data structures. HistoryAccording to D. Aldous and P. Diaconis ([1], p.417) patience sorting was first recognized as an algorithm to compute the longest increasing subsequence length by Hammersley ([2], p.362), and by A.S.C. Ross and independently Bob Floyd as a sorting algorithm. Initial analysis was done by Mallows [3]. References[1] David Aldous and Persi Diaconis. Longest increasing subsequences: from patience sorting to the Baik-Deift-Johansson theorem. Bull. (new series) of the Amer. Math. Society, Volume 36, number 4, pages 413–432 [2] J.M. Hammersley. A few seedlings of research. In Proc. Sixth Berkeley Symp. Math. Statist. and Probability, Volume 1, pages 345–394. University of California Press, 1972. MR 53:9457 [3] C.L. Mallows. Patience sorting. Bull. Inst. Math. Appl., 9:216–224, 1973. [4] Sergei Bespamyatnikh and Michael Segal. Enumerating Longest Increasing Subsequences and Patience Sorting. Pacific Inst. for the Math. Sci. Preprints, PIMS-99-3.
|
|
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License. |
|
| © 2008 Chamas Enterprises Inc. |