A homogeneous collection of elements that can be accessed using an index. It is fixed-size, typically contagious and is the most compact collection with no extra overhead per element.
Pros | Cons |
---|---|
Most compact collection | Fixed-size |
Indexable | Supports only one data type per array |
std::array<int, 3> arr = {1, 2, 3};
int[] arr = new int[3];
int[0] = 1;
from array import array
arr = array('l', [1, 2, 3])
arr[0] = 0
int arr[3] = {1, 2, 3}
arr[0] = 0;
Operations | Worst | Average |
---|---|---|
Index | O(1) | O(1) |