edited by
366 views
1 votes
1 votes
Deletion at ending
1. Linked list =O(n)
2. Array = O(1)
3. Dynamic array =O(1)
Correct?
But  given is O(n) for dynamic array
edited by

1 Answer

1 votes
1 votes

Yes it is O(n) for a dynamic array if we consider insertion at the end.This is so because , 

If we started out with a dynamic array of size 4, it would take constant time to push four elements onto it. Yet pushing a fifth element onto that array would take longer as the array would have to create a new array of double the current size (8), copy the old elements onto the new array, and then add the new element. The next four push operations would similarly take constant time, and then the subsequent addition would require another slow doubling of the array size.

In general if we consider an arbitrary number of pushes n to an array of size n, we notice that push operations take constant time except for the last one which takes O(n) time to perform the size doubling operation.

But if we want to find average case complexity , we see here that we have n operations  total we can take the average of this and find that for pushing elements onto the dynamic array takes O(n/n) = O(1) i.e. constant time.

Similarly , for deletion at the end , amortized complexity = O(1) time . Just follow the reverse of what we have done for insertion at end for dynamic array.

edited by

Related questions

0 votes
0 votes
3 answers
1
Desert_Warrior asked Apr 11, 2016
5,321 views
Consider a situation where a client receives packets from a server. There may be differences in speed of the client and the server. Which data structure is best suited fo...
0 votes
0 votes
0 answers
3
iarnav asked Jun 24, 2018
266 views
The number of possible min-heaps containing each value from {1,1,1,1,1,1,1} exactly once is _______This is a variance of Gate 2018 question and how will we deal if all va...