Exercise · Volume 1 · 2.2.4-17
Exercise 2.2.4-17
not stated yet in Lean solution written
| Rating | 22 |
|---|---|
| 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 what advantage there is in representing polynomials by circular lists rather than by linear lists ended by , as in the previous section.
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
Compare the algorithms of this section for the two kinds of list, and look for what differs.
Solution
Show the solution
There is very little to gain. The algorithms for addition and multiplication are nearly the same for both, since the test for the end of the list is made on the sentinel in one case and on in the other. The comparison with in the circular list can be replaced by a test for .
The one real difference is in freeing a polynomial. With a circular list the whole polynomial can be returned to the AVAIL list in a constant number of steps, as in Exercise 13. With a linear list one must run along the list to find its end, and the time is proportional to the number of terms. Since polynomials are often discarded, for example after a product has been formed, this matters. A second small gain is that the zero polynomial and the others are all alike, a sentinel and the terms after it, with no special case for the empty list.
Remarks
For other uses, such as queues and rings of items, the circular list has more to offer, as the text shows in the section.
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.