In the video, i learned that the capacity of the vector doubles as we add an element when it crosses the previous capacity. Does it significantly affect time because I feel average time will be O(n) if we have many elements.
Capacity of vector
so O(n) is a good amount of time
like u copy the entire elements of old vector into the new vector and hence contributes to O(N ) complexity
No, no!. What i mean to say is so assume i am starting with capacity 1 and want to add 1024 elements. So when i add the element when the capacity is full it will double right. Doubling will happen at 1,2,4,8,16,32,64,128,256,512,1024. So it happens total 10 times so is it significantly affecting my time. total time complexity of adding all 1024 elements is almost O(1024). Please let me know if I am going wrong.
to dekho yr
agar initially u did not say ki size 1024 se bada h
vector vec
kar dia
to 1 ke bad jab 2 capacity hogi to firse 1 element nayi aray meh hoga allocate
thne jab 17th element
to nayi array banegi
to har bar copy meh time lagega
na
to time to increase ho he raha h
as compared to when u declare vectorvec(1025,0)