Exercise · Volume 1 · 2.2.4-12
Exercise 2.2.4-12
not stated yet in Lean solution written
| Rating | 21 |
|---|---|
| Kind | K7, analyze: find the mean, the variance or the distribution of a cost from the written solution |
| Section | Section 2.2.4 of Volume 1 |
The task
Compare the running time of the subroutine of Exercise 11 with that of Program A when .
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
To copy by addition one first has to make a zero polynomial. Count that time too.
Solution
Show the solution
Let have terms. With every term of is a term that is not in , so it is copied by Program A, and the time of Program A is units, plus for the call and the return. For a fair comparison the zero polynomial must be made first, and the subroutine of Exercise 14 below takes units with its call. The copy by addition costs units.
The subroutine of Exercise 11 takes units. The difference is , so the subroutine of Exercise 11 is the faster one. For large its time is , which is about , of the other.
Check
In the simulator, for , a call to ZERO followed by Program A took , and units, which is , and COPY took , and , which is .
Remarks
Program A spends units on a term that is added to nothing because it has to compare, find that is larger, and insert. COPY knows from the start that every term is new.
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.