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.5-12

Exercise 2.2.5-12

not stated yet in Lean solution written

Rating22
KindInformal: the exercise has no formal statement, so Lean does not state it from the written solution
SectionSection 2.2.5 of Volume 1

The task

Explain why doubly linked lists are a good choice in the simulation program, rather than singly linked or sequential lists.

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

Find the places where a node is removed from a list when only the node itself is known.

Solution

Show the solution

The program removes nodes from the middle of its lists, given only the node. A user who gives up, step U4, leaves a queue from any place. A user who is sent to U5 or U6 by the elevator, and the activities E5 and E9 that are cancelled when the elevator starts to move, come out of the WAIT list wherever they are. In all these cases a singly linked list would need a walk from the beginning to find the predecessor, and a sequential table would need a shift of all later entries. The doubly linked list deletes in constant time by operation (4) of the text.

Another reason is the way the WAIT list is used. It is read at the left end, since the first node is the next event. New nodes are placed by a search from the right end, because the new events tend to be late. So the list is used in both directions.

Only the ELEVATOR list could be made singly linked without much loss.

Remarks

For a long WAIT list a tree would be better than the sorted list, because insertion takes time proportional to the length. Section 5.2.3 treats such priority queues.

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.