Sunteți pe pagina 1din 1

Algorithms & Complexity Theory

Ammortised Analysis Errata

The cost of a sequence S of size n of operations of type insert, performed


on an initially empty arraylist is given by:
cost(S) = cost copy(S) + cost ins(S)
We analyse cost copy(S). We observe that:
2k1 < n 2k
for some k N. Moreover, k represents the number of times the arraylist
capacity was doubled. It follows that: k 1 < log(n) k, and thus k =
dlog(n)e. The cost of the ith doubling is 2i1 , hence:
dlog(n)e

cost copy(S) =

X
i=1

dlog(n)e1

2i1 =

log(n)

2i

i=0

X
i=0

It follows that:
cost(S) 3n

2i = 2log(n)+1 1 = 2n 1

S-ar putea să vă placă și