Algorithm For Finding A Longest Increasing Subsequence
First, execute the sorting algorithm as described above. The number of piles is the length of a longest 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 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.
Read more about this topic: Patience Sorting
Famous quotes containing the words finding, longest and/or increasing:
“I do not know what I may appear to the world; but to myself I seem to have been only like a boy playing on the seashore, and diverting myself in now and then finding a smoother pebble or a prettier shell than ordinary, whilst the great ocean of truth lay all undiscovered before me.”
—Isaac Newton (16421727)
“Freud is all nonsense; the secret of neurosis is to be found in the family battle of wills to see who can refuse longest to help with the dishes. The sink is the great symbol of the bloodiness of family life.”
—Julian Mitchell (20th century)
“Major [William] McKinley visited me. He is on a stumping tour.... I criticized the bloody-shirt course of the canvass. It seems to me to be bad politics, and of no use.... It is a stale issue. An increasing number of people are interested in good relations with the South.... Two ways are open to succeed in the South: 1. A division of the white voters. 2. Education of the ignorant. Bloody-shirt utterances prevent division.”
—Rutherford Birchard Hayes (18221893)