
LESSON CONTENT
Inserting an element into an array means adding a new value at a specific position. Because arrays use consecutive memory, making space for a new element often requires shifting other elements.
If the array has extra capacity, adding an element to the end is fast. The new value is placed directly after the last existing element, and no shifting is needed.
When inserting at an index somewhere in the middle, every element from that index onward must move one position to the right. This shifting keeps elements in order but increases the cost of insertion.
Inserting early in a large array may require shifting many elements. The more elements that need to move, the slower the operation becomes.
Deleting an element removes a value from a specific index. Because arrays must stay packed tightly in memory, removing an element creates a gap that must be filled by shifting the following elements.
Removing the last element is efficient. No shifting is required, and the array simply becomes one element shorter.
When deleting from the middle of an array, each element to the right must move one step left to fill the empty position and maintain consecutive memory.
Like insertion, deletion becomes slower as the number of elements increases. If many elements must shift left, the deletion cost grows.