#I dont understand this concept can someone explain

1 messages · Page 1 of 1 (latest)

outer sand
#

Case: expand by 1
Initial Capacity = 1 Assume m append() calls
Capacity=1 2 34 5 6 78... ....m Total Cost for all m append()’s =
cost of appending + cost of allocation/freeing + cost of copying cost of appending (setting m elements) =
cost of allocation/freeing =
m x constant
m x constant
cost of copying =
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + .... + (m-1)
=~ m x (m + 1)/2 =~ m2/2
Total Cost = m x constant + m x constant + m2/2 ~ m2 Average/Amortized cost per append() = m2/m = m à Θ(n)

mystic thistleBOT
#

This post has been reserved for your question.

Hey @outer sand! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.