taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 2.2.1-6

Exercise 2.2.1-6

not stated yet in Lean solution written

Rating00
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 2.2.1 of Volume 1

The task

Say which permutations of 12…n12\ldots n a queue can give.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

A queue gives up its items in the order of their arrival.

Solution

Show the solution

Only the identity permutation 12…n12\ldots n. The cars enter the queue in the order 1,2,…,n1, 2, \ldots, n. A queue always removes its oldest item, so the cars leave in the order in which they came in. Every move sequence ends with the output 12…n12\ldots n.

Check

I ran a queue on all legal sequences of inserts and removals for n=1,…,6n = 1, \ldots, 6. The output was 12…n12\ldots n each time.

Remarks

A queue keeps the order of the input. A stack reverses a block of it. The deque of the following exercises can do more than either.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.