Skip to content

Array in Memory Visualizer

Watch array elements sit side by side in memory, shift on insert and delete, and move when the array grows.

Length: 0 Capacity: 0 Element size: 4 bytes Element moves: 0
  • Reading
  • Writing
  • Found or new
  • Free capacity
Step 1 of 1

get(i):  address = base + i × elementSize  return memory[address]            // O(1)append(x):  if length = capacity: grow()  a[length] = x; length = length + 1insert(i, x):  if length = capacity: grow()  for k = length − 1 down to i    a[k + 1] = a[k]                  // shift right  a[i] = x; length = length + 1delete(i):  for k = i to length − 2    a[k] = a[k + 1]                  // shift left  length = length − 1grow():  newBlock = allocate(capacity × 2)  copy a[0 .. length − 1] to newBlock  free the old block; a = newBlocksearch(x):  for i = 0 to length − 1: if a[i] = x: return i  return −1
Dynamic array operations
OperationTime
Access a[i]O(1)
AppendO(1) amortized, O(n) when it grows
Insert at indexO(n)
Delete at indexO(n)
Search (unsorted)O(n)
Search (sorted, binary)O(log n)
SpaceO(n), up to 2n with doubling

An array is the simplest data structure: a block of memory where every element has the same size and sits right after the previous one. This visualizer draws that block as a row of memory cells, each with its index, its value and its real memory address. Pick an element type such as int (4 bytes), long or double (8 bytes) or char (1 byte) and a base address, and you see every address change to base + index × size.

Then try the operations. Accessing a[i] takes a single step because the address is computed, not searched. Inserting or deleting in the middle shifts every later element one cell, which is why those operations are O(n). Append to a full array and you see what a dynamic array (ArrayList in Java, std::vector in C++, list in Python) does: it allocates a block twice as big, copies the elements over and frees the old block.

How to use the Array in Memory Visualizer tool

  1. Choose the element type and, if you like, a different base address in hex.
  2. Type a value and an index, then press Access a[i], Append, Insert at index, Delete at index or Search value.
  3. Watch the animation. Orange cells are being read, red cells are being written and green cells hold the new or found value.
  4. Use Step and Back to go through a shift or a resize one element at a time, and read the address formula under the cells.
  5. Keep appending until the array is full to see the capacity double and the elements copied to a new block.

Why use ToolOrca Array in Memory Visualizer

  • Memory cells with index, value and hexadecimal address
  • int, long, char and double element sizes
  • Address formula shown for every access
  • Animated shifting on insert and delete
  • Capacity doubling with copy to a new block
  • Length, capacity and element-move counters
  • Code for a dynamic array in C++, Java, Python and JavaScript

How an array is stored in memory

When a program creates an array, it asks for one contiguous block of memory big enough for all the elements. If the block starts at the base address B and every element takes S bytes, element i lives at B + i × S. An int array starting at 0x1000 puts a[0] at 0x1000, a[1] at 0x1004 and a[5] at 0x1014. This is why array indexes start at 0 in C, C++, Java, Python and JavaScript: the index is simply the distance from the start.

Because the address is a calculation, reading or writing any element costs the same tiny amount of time no matter how big the array is. That is O(1) random access, the big advantage of arrays over linked lists. Elements that sit next to each other are also loaded into the CPU cache together, so looping over an array is very fast in practice.

Insert, delete and dynamic arrays

There are no gaps in an array, so inserting at index i means moving every element from i to the end one place to the right first, and deleting means moving them back left. In the worst case (index 0) that is n moves, so insert and delete are O(n). Adding or removing at the end needs no shifting and is O(1).

A fixed array cannot grow, because the memory after it may belong to something else. A dynamic array solves this by keeping some spare capacity. When it is full it allocates a new block, usually 1.5 or 2 times larger, copies everything and frees the old one. Copying n elements is expensive, but it happens so rarely that the average (amortized) cost of append stays O(1). The complexity table under the visualizer sums up every operation.

When to use an array

Use an array (or a dynamic array) when you need fast access by position, when you mostly add at the end, and when you loop over the data often. Choose a linked list instead only when you insert and delete in the middle very often and already hold a pointer to the place, or when elements must never move in memory.

Every visualizer on this site runs in your browser with the same controls: Play, Pause, Step forward, Step back and a speed slider. You can also drag the position slider to jump to any step, or focus the drawing and use the Space bar and arrow keys.

Frequently asked questions

How do you calculate the address of an array element?

Address of a[i] = base address + i × element size. For an int array (4 bytes) starting at 0x1000, a[3] is at 0x1000 + 3 × 4 = 0x100C.

Why is array access O(1)?

Because the computer works out the address with one multiplication and one addition. It does not have to visit the elements before it, so the time does not depend on the size of the array.

Why are insert and delete O(n) in an array?

Elements must stay next to each other, so every element after the position has to move one place. Inserting at the front of an array of n elements moves all n of them.

What happens when a dynamic array is full?

It allocates a bigger block (often double the capacity), copies all the elements into it and frees the old block. Because this happens rarely, append is still O(1) on average, called amortized O(1).

What is the difference between length and capacity?

Length is how many elements are stored. Capacity is how many fit in the current block before it must grow. A vector with length 5 and capacity 8 has 3 free slots.