Exercise1-13 <---> Exercise1-15
Exercise 1.14
Draw the tree illustrating the process generated by the count-change procedure of section 1.2.2 in making change for 11 cents. What are the orders of growth of the space and number of steps used by this process as the amount to be changed increases?
Ru: Нарисуйте дерево, иллюстрирующее процесс, который порождается процедурой count-change из раздела 1.2.2 при размене 11 центов. Каковы порядки роста памяти и числа шагов, используемых этим процессом при увеличении суммы, которую требуется разменять?
Solution:
To determine the order of growth of space we look at the longest path in the tree generated by the process count-change. Let
The root of the tree is
. The two vertexes that join this node are
and
. We want to decrease
as slow as possible, for when
the path ends. To do this, we first follow the edges
because
. The length of this first piece of the path is
. Now we follow the edges
. This part of the path has length
, so the total length of the longest path is
which is
.
The attached countingcoins.pdf shows a rough proof (attempt anyway) that the order of growth of time (number of function calls is THETA(n^c)) where c is the number of types of coins.
Exercise1-13 <---> Exercise1-15