Skip to content

Arrays ​

An array is a data structure used to store multiple elements. Arrays can be single or multi-dimensional (2d).

Time complexity of array operations ​

OperationMethodComplexity
Append to endpush()O(1)
Popping from endpop()O(1)
Insert, not from endsplice()O(n)
Delete, not from endsplice()O(n)
Modify an elementby indexO(1)
Random accessby indexO(1)
Check if existstraverseO(n)

Subarray ​

A contiguous part of an array.

Example: [1, 2, 3] => [1, 2], [2, 3]

Subset ​

A collection of elements from an array in order. It can be solved using recursion or iteration.

Example: [1, 2, 3] => [1], [1, 2], [1, 2, 3], [2], [2, 3], [3]