Average Time per Insertion Operation in Dynamic Array is a/(a-1)
On the wikipedia article on Dynamic Arrays it mentions (apart from the normal section on amortised insertion time) that:
The value of this proportion a [the constant factor by which we increase the capacity] leads to a time-space tradeoff: the average time per insertion operation is about a/(a−1), while the number of wasted cells is bounded above by (a−1)n.
I can see where the (a-1)n for wasted cells com开发者_开发问答es from but can anyone explain to me why the average time is a/(a-1)?
Let S be the time to insert n elements.
- In these n elements, there are n elements cost at least 1 allocation.
- In these n elements, there are n/a elements cost at least 2 allocation.
- In these n elements, there are n/a^2 elements cost at least 3 allocation.
- ...
Therefore a/(a-1) is the average complexity to insert an element.
精彩评论