4. With respect to arrays, establish the relationship between the size of the array and the time it takes to perform an insertion at the beginning of the array. Provide empirical evidence to support your answer.
Arrays are linear data structures that contains a single type of data.
While accessing an element, traversal always start from 1st element (or 0th index).
Also, elements are always placed from left to right. So, at no block in the left side of array can unfilled while right is filled.
For insertion at 0th index (beginning) we must first empty 0th
element by shifting the array by a block towards right and then
insert at 0th element.
The right swap by a block takes O(n) time
complexity.
So, insertion at beginning would take O(n) time in an
array.
The steps would be:
Note: G here corresponds to a Garbage value. The array is
filled upto index 5 only.
The swap takes O(n) in array.
Hope it helps.
Get Answers For Free
Most questions answered within 1 hours.