Name: Anonymous 2015-05-04 23:22
How often is the answer to a tricky programming problem to use a fancy data structure?
No, it's still Θ(n). You have to allocate a new, larger array, then copy all the n items from the old array to the new, then free the memory taken up the the old array.
size
and capacity
vars. size
is the number of elements in the array. capacity
is the memory allocated to the array. size
is always less than capacity
. e.g. Initialize with size = 0
and capacity = 1024
. That gives you 1024 O(1) append operations before capacity
needs to be increased and objs
needs to be reallocated. It's Θ(1), trust me.