In: Computer Science
1. With respect to resizable arrays, establish the relationship between the size of the array and the time it takes to perform random access (read a the value stored at a given position somewhere in the array). Provide empirical evidence to support your answer.
A resizable array or dynamic array is an array whose size changes when it becomes full. Generally, the size is doubled each time the insertion is required when array becomes full.
For accessing the element at certain index, the time complexity is always O(1)
In case of searching for a value in each index, the time complexity becomes O(n) in static array.
Considering that the size doubles each time the array exceeds, let us assume that at certain point the array has been doubled k times. Now the size of array becomes 2k*n.
At this instance the search for a specific value would take at
most (2k*n) steps.
Since n is taken as a very large number for time
complexity, 2k can be considered as a constant for low
values of k.
Hence, time complexity
becomes O(n).
SUMMARY
For search at an specific index, time complexity is
O(1). and
For searching a value in the array, time complexity is
O(n).
both in resizabe (dynamic) as well as non-resizable (static)
array.
Hope it helps.