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.1-1

Exercise 2.1-1

not stated yet in Lean solution written

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

The task

Read two values from the picture of the card pile: the suit of the second card, and the link in the third card.

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

Start from the picture (3). Each box is a node, and TOP points to the first node.

Hint 2

NEXT(X) is the link stored in the node that X points to. Apply it from the inside out.

Solution

Show the solution

TOP points to the first node, which is at address 242242. By (2), the NEXT field of this node holds 386386, so NEXT(TOP) = 386. The node at 386386 has SUIT = 4, which stands for spades. So (a) SUIT(NEXT(TOP)) = 4.

For (b), NEXT(TOP) = 386 and NEXT(386) = 100. The node at 100100 is the bottom card, and its NEXT field is the null link. So NEXT(NEXT(NEXT(TOP))) = \Lambda.

Check

Count the cards: there are three nodes, so a chain of three NEXT steps from TOP must leave the pile. The chain is 242→386→100→Λ242 \to 386 \to 100 \to \Lambda.

Remarks

The answer to (b) is the null link and not a node, so no field can be taken of it. An algorithm that follows NEXT must test for Λ\Lambda before it goes on, as the counting algorithm of the section does.

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.