Arrays
What’s special about arrays?
Constant time access
Multi-Dimensional
(1,1) (1,1)
(1,2) (2,1)
Row-major (1,3) (3,1) Column-Major
(1,4) (1,2)
(2,1) (2,2)
… …
Times for common operations
Add | Remove | |
---|---|---|
Beginning | O(n) | O(n) |
End | O(1) | O(1) |
Middle | O(n) | O(n) |
Summary
- Array: contiguous area of memory consisting of equal-size elements indexed by contiguous integers.
- Constant access to any element.
- Constant time to add/remove at the end.
- Linear time to add/remover at an arbitrary location.