开发者

Average Time per Insertion Operation in Dynamic Array is a/(a-1)

开发者 https://www.devze.com 2023-03-23 02:48 出处:网络
On the wikipedia article on Dynamic Arrays it mentions (apart from the normal section on amortised insertion time) that:

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.
  • ...

Average Time per Insertion Operation in Dynamic Array is a/(a-1)

Therefore a/(a-1) is the average complexity to insert an element.

0

精彩评论

暂无评论...
验证码 换一张
取 消