ArticleslgStudy

science

Stack-sortable permutation

Stack-sortable permutation is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Stack-sortable permutation rather than just read about it. In short: In mathematics and computer science, a stack-sortable permutation (also called a tree permutation) is a permutation whose elements may be sorted by an algorithm whose internal storage is limited to a single stack data structure. The stack-sortable permutations are exactly the permutations that do not contain the permutation pattern 231; they are counted by the Catalan numbers, and may be placed in bijection with man…

Stack-sortable permutation — main illustration
Stack-sortable permutation — illustration

Key takeaways

  • Stack-sortable permutation belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Stack-sortable permutation to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Stack-sortable permutation from memory before moving on to harder problems.

Reference excerpt

In mathematics and computer science, a stack-sortable permutation (also called a tree permutation) is a permutation whose elements may be sorted by an algorithm whose internal storage is limited to a single stack data structure. The stack-sortable permutations are exactly the permutations that do not contain the permutation pattern 231; they are counted by the Catalan numbers, and may be placed in bijection with many other combinatorial objects with the same counting function including Dyck paths and binary trees.

Sorting with a stack The problem of sorting an input sequence using a stack was first posed by Knuth (1968), who gave the following linear time algorithm (closely related to algorithms for the later all nearest smaller values problem):

Initialize an empty stack For each input value x: While the stack is nonempty and x is larger than the top item on the stack, pop the stack to the output Push x onto the stack While the stack is nonempty, pop it to the output Knuth observed that this algorithm correctly sorts some input sequences, and fails to sort others. For instance, the sequence 3,2,1 is correctly sorted: the three elements are all pushed onto the stack, and then popped in the order 1,2,3. However, the sequence 2,3,1 is not correctly sorted: the algorithm first pushes 2, and pops it when it sees the larger input value 3, causing 2 to be output before 1 rather than after it. Because this algorithm is a comparison sort, its success or failure does not depend on the numerical values of the input sequence, but only on their relative order; that is, an input may be described by the permutation needed to form that input from a sorted sequence of the same length. Knuth characterized the permutations that this algorithm correctly sorts as being exactly the permutations that do not contain the permutation pattern 231: three elements x, y, and z, appearing in the input in that respective order, with z < x < y. Moreover, he observed that, if the algorithm fails to sort an input, then that input cannot be sorted with a single stack. As well as inspiring much subsequent work on sorting using more complicated systems of stacks and related data structures, Knuth's research kicked off the study of permutation patterns and of permutation classes defined by forbidden patterns.

Bijections and enumeration The sequence of pushes and pops performed by Knuth's sorting algorithm as it sorts a stack-sortable permutation form a Dyck language: reinterpreting a push as a left parenthesis and a pop as a right parenthesis produces a string of balanced parentheses. Moreover, every Dyck string comes from a stack-sortable permutation in this way, and every two different stack-sortable permutations produce different Dyck strings. For this reason, the number of stack-sortable permutations of length n is the same as the number of Dyck strings of length 2n, the Catalan number

C n = 1 n + 1 ( 2 n n ) . {\displaystyle C_{n}={\frac {1}{n+1}}{\binom {2n}{n}}.}

Stack-sortable permutations may also be translated directly to and from (unlabeled) binary trees, another combinatorial class whose counting function is the sequence of Catalan numbers. A binary tree may be transformed into a stack-sortable permutation by numbering its nodes in left-to-right order, and then listing these numbers in the order they would be visited by a preorder traversal of the tree: the root first, then the left subtree, then the right subtree, continuing recursively within each subtree. In the reverse direction, a stack-sortable permutation may be decoded into a tree in which the first value x of the permutation corresponds to the root of the tree, the next x − 1 values are decoded recursively to give the left child of the root, and the remaining values are again decoded recursively to give the right child. Several other classes of permutations may also be placed in bijection with the stack-sortable permutations. For instance, the permutations that avoid the patterns 132, 213, and 312 may be formed respectively from the stack-sortable (231-avoiding) permutations by reversing the permutation, replacing each value x in the permutation by n + 1 − x, or both operations combined. The 312-avoiding permutations are also the inverses of the 231-avoiding permutations, and have been called the stack-realizable permutations as they are the permutations that can be formed from the identity permutation by a sequence of push-from-input and pop-to-output operations on a stack. As Knuth (1968) noted, the 123-avoiding and 321-avoiding permutations also have the same counting function despite being less directly related to the stack-sortable permutations.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Stack-sortable permutation

Start with the simplest possible case. Write down what Stack-sortable permutation claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Stack-sortable permutation before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Stack-sortable permutation ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Stack-sortable permutation

In research
Stack-sortable permutation appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Stack-sortable permutation in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Stack-sortable permutation is common in secondary-school and first-year university syllabi. It links to neighbouring topics Permutation patterns, so understanding it makes those chapters shorter.
In everyday life
Look for Stack-sortable permutation outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Stack-sortable permutation” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Stack-sortable permutation in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Stack-sortable permutation means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Stack-sortable permutation out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Stack-sortable permutation in simple terms?

In mathematics and computer science, a stack-sortable permutation (also called a tree permutation) is a permutation whose elements may be sorted by an algorithm whose internal storage is limited to a single stack data structure. The stack-sortable permutations are exactly the permutations that do n…

Why does Stack-sortable permutation matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Stack-sortable permutation?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Stack-sortable permutation.

Tags

  • Permutation patterns

Keep exploring