Exercise · Volume 1 · 2.2.4-7
Exercise 2.2.4-7
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 it is useful to keep the fields of a polynomial list in decreasing order.
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
Think about how Algorithm A finds, for a term of , the term of with the same exponents.
Solution
Show the solution
With a fixed order both lists can be scanned once, side by side. For a term of the pointer in moves forward until it reaches an that is not larger. If it is equal, the terms are added. If it is smaller, the term is inserted before it. The pointer into never goes back, so the whole addition is one pass over both lists, and the time is linear in the sum of their lengths. Without any order one would search from the start for each term of , which takes time proportional to the product of the lengths.
The decreasing order also fits the sentinel. The sentinel has , which is smaller than every real term, so it comes last in a decreasing list. It stops the scan of in the same way as any smaller term. In an increasing order the smallest value would have to be at the front, and the sentinel with would have to be at the front, where it could not serve as the stop of the loop.
Remarks
Another way to say this is that the lists are sorted lists and addition is a merge. The merge works only because both lists use the same order.
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.