← Back

Array Simulator

What is an Array?

An array stores elements in an indexed sequence. In the classical fixed-size array model, elements occupy contiguous memory locations, enabling direct access by index.

AccessO(1)
Linear searchO(n)
Insert/deleteO(n)
Bubble SortO(n²)

Create and edit the array

350 ms

Create an array or select an operation.

Current operationIdle
Comparisons0
Swaps / shifts0
Complexity

Array concepts

Index-based access

An array address can be calculated from its base address, element size, and index. This is why reading array[i] takes O(1) time.

Insertion and deletion

Inserting or deleting in the middle requires shifting later elements. The simulator visualizes this behavior even though JavaScript arrays are dynamic.

Linear search

Linear search checks elements from left to right until it finds the target or reaches the end. Its worst-case running time is O(n).

Bubble Sort

Bubble Sort repeatedly compares adjacent values and swaps them when they are out of order. The optimized version stops early when a complete pass performs no swaps.

Typical time complexities

Operation Typical time Reason
Access by index O(1) The address is calculated directly.
Set by index O(1) The target position is known.
Linear search O(n) Every element may need to be checked.
Insert/delete in the middle O(n) Later elements may need to shift.
Reverse O(n) Pairs are swapped from both ends.
Bubble Sort O(n²) Nested passes compare adjacent elements.