05 Vectors PDF
05 Vectors PDF
05 Vectors PDF
1
Vectors 4/1/2003 9:03 AM
Deletion Performance
In operation removeAtRank(r), we need to fill the In the array based implementation of a Vector
hole left by the removed element by shifting The space used by the data structure is O(n)
backward the n − r − 1 elements V[r + 1], …, V[n − 1]
size, isEmpty, elemAtRank and replaceAtRank run in
In the worst case (r = 0), this takes O(n) time O(1) time
insertAtRank and removeAtRank run in O(n) time
V o If we use the array in a circular fashion,
0 1 2 r n
insertAtRank(0) and removeAtRank(0) run in
V O(1) time
0 1 2 r n In an insertAtRank operation, when the array
V is full, instead of throwing an exception, we
0 1 2 r n can replace the array with a larger one
4/1/2003 9:03 AM Vectors 7 4/1/2003 9:03 AM Vectors 8