Skip to content
Snippets Groups Projects
Commit bb8f0814 authored by Martin Mareš's avatar Martin Mareš
Browse files

Preliminaries: Corrections by Vašek K.

parent 8e5c3ecf
Branches
No related tags found
No related merge requests found
......@@ -269,7 +269,7 @@ to happen.
Now, we turn our attention to an~$\ell$-bit binary counter. Initially, all its bits are zero. Then we keep
incrementing the counter by~1. For $\ell=4$, we get the sequence \|0000|, \|0001|, \|0010|, \|0011|, \|0100|, and~so on.
Performing the increment it simple: we scan the number from the right, turning \|1|s to \|0|s,
Performing the increment is simple: we scan the number from the right, turning \|1|s to \|0|s,
until we hit a~\|0|, which we change to a~\|1| and stop.
A~single increment can take $\Theta(\ell)$ time when we go from \|0111|\dots\|1| to \|1000|\dots\|0|.
......@@ -282,13 +282,13 @@ number of changes will therefore be:
$$
\sum_{i=0}^{\ell-1} \left\lfloor {n\over 2^i} \right\rfloor \le
\sum_{i=0}^{\ell-1} {n\over 2^i} \le
n\cdot\sum_{i=0}^\ell {1\over 2^i} \le
n\cdot\sum_{i=0}^{\ell-1} {1\over 2^i} \le
n\cdot\sum_{i=0}^\infty {1\over 2^i} = 2n.
$$
However, there is an~easier and ``more economical'' approach to analysis.
Imagine that we have some \em{coins} and each coin buys us a~constant amount of computation time,
enough to test and change one bit. We will maintain an invariant that for every~\|1| bit, we have
enough to test and change one bit. We will maintain an invariant that for every~\|1|, we have
one coin --- we can imagine that the coin is ``placed on the bit''.
When somebody comes and requests an increment, we ask for 2~coins. This is enough to cover the
......@@ -310,7 +310,7 @@ those which spend the savings later.)
\subsection{The potential method}
In the above examples, the total complexity of a~sequence of operations was much better
that the sum of their worst-case complexities. The proof usually involved increasing the
than the sum of their worst-case complexities. The proof usually involved increasing the
cost of ``easy'' operations to compensate for an occassional ``hard'' one. We are going
to generalize this approach now.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment