Arrays
Contiguous memory · instant access by indexAn array stores elements side by side in memory, so the computer can jump straight to any index — but inserting or deleting in the middle means shifting other elements. Try it below and watch it happen.
- Index starts at 0first element is arr[0]
- Fixed capacity10 slots
- O(1) accessaddress = base + i × size
- Current
- Comparing
- Found / new
- Removing
- Empty slot
Ready
Keyboard: ← → step · Space play / pause · R reset · Esc exit classroom mode
Every operation, in plain steps
These are exactly the steps the visualizer animates.
Insert
- Check there is free space (size < capacity).
- Shift every element from the last one down to the position one step right.
- Place the new value in the free slot.
- Increase the size by 1.
Delete
- Check the array is not empty.
- Remove the value at the position.
- Shift every element after it one step left to close the gap.
- Decrease the size by 1.
Search (linear)
- Start at index 0.
- Compare each element with the target.
- Stop as soon as you find a match.
- If you reach the end, the value is not there (-1).
Update
- Calculate the address: base + index × element size.
- Jump straight to that slot — no searching.
- Overwrite the old value with the new one.
Pseudocode
Language-independent steps. The visualizer shows the same logic in C, Python and Java.
How fast is each operation?
n = number of elements. Every operation uses O(1) extra space.
| Operation | Best | Average | Worst | Speed |
|---|---|---|---|---|
| Access / Update | O(1) |
O(1) |
O(1) |
Instant |
| Insert | O(1) |
O(n) |
O(n) |
Grows with n |
| Delete | O(1) |
O(n) |
O(n) |
Grows with n |
| Linear Search | O(1) |
O(n) |
O(n) |
Grows with n |
| Traverse | O(n) |
O(n) |
O(n) |
Grows with n |
Check your understanding
Answer each question — you will see the explanation straight away.
In arr = [10, 20, 30, 40, 50], at which index is the value 30 stored?
Indexes start at 0, so 10 is at 0, 20 at 1 and 30 at index 2.
You insert a value at index 0 of an array holding n elements. How many elements must be shifted?
Every one of the n elements moves one step right to free index 0 — that is why insertion at the front is O(n).
Why can an array read arr[i] in O(1) time?
Elements sit next to each other in memory, so the address of any index is one simple calculation.
Deleting the LAST element of an array needs how many shifts?
Nothing comes after the last element, so no shifting is needed — the best case, O(1).
Arrays quiz
Test yourself: 5 questions, 70% to pass. Create a free account to take the quiz, save your progress and work towards the certificate.