Array
Contiguous memory blocks. Access any element in O(1) using its index — the backbone of all data structures.
Access O(1)Search O(n)Insert O(n)Space O(n)
Visualization
5
[0]
12
[1]
3
[2]
8
[3]
19
[4]
7
[5]
14
[6]
Complexity Analysis
O(1)
O(log n)
O(n)
O(n log n)
O(n²)
| Operation | Complexity | At n=50 | Growth |
|---|---|---|---|
| Access | O(1) | 1 | |
| Search | O(n) | 50 | |
| Insert | O(n) | 50 | |
| Delete | O(n) | 50 |
Space:O(n)auxiliary memory
Index-based access is instant. Insertions and deletions cost O(n) because every element after the target must shift.
Pseudocode
// Access by index — O(1)
arr[i]
// Linear Search — O(n)
for i in 0..n:
if arr[i] == target: return i
// Insert at end — O(1) amortized
arr.push(val)
// Insert at index — O(n) shifts
arr.splice(idx, 0, val)
// Delete at index — O(n) shifts
arr.splice(idx, 1)