Exercise · Volume 1 · 2.2.4-8
Exercise 2.2.4-8
not stated yet in Lean solution written
| Rating | 10 |
|---|---|
| Kind | Informal: the exercise has no formal statement, so Lean does not state it from the written solution |
| Section | Section 2.2.4 of Volume 1 |
The task
Explain why Algorithm A keeps one step behind .
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
Ask what a deletion or an insertion before needs to know.
Solution
Show the solution
A node can be removed from a linked list only if we know the node that points to it, because that node's link must be changed. In Algorithm A, when two terms cancel, the node is removed from the polynomial. When a term of is not in , a new node must be put in front of . Both actions change the link of the node before , and the lists are one-way, so this node cannot be found from without a new walk. The pointer holds it all the time.
There are ways without . To delete one can copy the next node into it and free the next node. To insert before one can put the new node after it and exchange the contents of the two nodes. These tricks work, but they move nodes. In the polynomial lists the last node, the sentinel, would sometimes be moved, and then any other variable that points at the sentinel, for example the pointers and that stand for the polynomials, would point to a wrong place. The extra pointer is the cheaper and safer choice.
Remarks
The extra pointer costs one register, and in Program A it also costs one instruction to advance it in each step.
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.