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

Preliminaries: There is no stretch with k=0

parent bfe96d05
Branches
No related tags found
No related merge requests found
...@@ -191,10 +191,10 @@ initial capacity is~1 and we always double capacity on reallocations. Then the c ...@@ -191,10 +191,10 @@ initial capacity is~1 and we always double capacity on reallocations. Then the c
$k$~reallocations will be exactly~$2^k$. $k$~reallocations will be exactly~$2^k$.
If we appended $n$~items, all reallocations together take time If we appended $n$~items, all reallocations together take time
$\Theta(2^0 + 2^1 + \ldots + 2^k)$ $\Theta(2^1 + 2^2 + \ldots + 2^k)$
for~$k$ such that $2^{k-1} < n \le 2^k$ (after the $k$-th reallocation the array was large enough, for~$k$ such that $2^{k-1} < n \le 2^k$ (after the $k$-th reallocation the array is large enough,
but it wasn't before). This implies that $n \le 2^k < 2n$. but it wasn't before). This implies that $n \le 2^k < 2n$.
Hence $2^0 + \ldots + 2^k = 2^{k+1}-1 \in \Theta(n)$. Hence $2^1 + \ldots + 2^k = 2^{k+1}-2 \in \Theta(n)$.
We can conclude that while a~single append can take $\Theta(n)$ time, all $n$~appends also take $\Theta(n)$ We can conclude that while a~single append can take $\Theta(n)$ time, all $n$~appends also take $\Theta(n)$
time, as if each append took constant time only. We will say that the amortized complexity of a~single append time, as if each append took constant time only. We will say that the amortized complexity of a~single append
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment