Data Structures & AlgorithmsVery hard

A linear-time check decides whether a permutation can be sorted by one stack. Which property is equivalent to being stack-sortable?

  1. A. The permutation has no pattern 231 (no i < j < k with a[k] < a[i] < a[j]).
  2. B. The permutation has no two adjacent descents.
  3. C. The permutation's first element is 1.
  4. D. The permutation is an involution.

Correct answer: A. The permutation has no pattern 231 (no i < j < k with a[k] < a[i] < a[j]).

Stack-sortable permutations are exactly the 231-avoiding ones, which is a classic characterization. The other properties are either too weak or unrelated.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic