Basic Operations

Every data structure is defined by the operations you can perform on it. Here are the core operations for arrays:

OperationTimeSpaceNotes
Access by indexO(1)O(1)Direct calculation using address formula
Search (unsorted)O(n)O(1)Must check every element
Search (sorted)O(log n)O(1)Binary search
Insert at endO(1)O(1)O(n) if array needs resizing
Insert at positionO(n)O(1)Must shift elements right
Delete at endO(1)O(1)Just decrement size
Delete at positionO(n)O(1)Must shift elements left
Find min/maxO(n)O(1)Must scan entire array

Quick Check

What is the time complexity of inserting an element at the beginning of an array of size n?