Algorithms / 9 visualizations
Linked List, Stack and Queue Visualizers
Pointer moves on linked lists, merging sorted lists, stacks, queues and ring buffers.
Open the lab → Every one runs on your own input, step by step, with the code highlighted in Java, Python, C++, C or JavaScript. Free, no sign-up.
All lists, stacks & queues visualizations
- Reverse a Linked ListO(n)
Walk the list once. At each node, save next, point the node back to prev, then move prev and curr one step forward.
- Floyd's Cycle DetectionO(n)
slow moves 1 step, fast moves 2. With a cycle, fast laps slow and they meet. Without one, fast reaches null.
- Remove the Nth Node From the EndO(n)
Move fast n + 1 steps ahead of slow. Then move both until fast falls off the end: slow now sits just before the node to remove.
- Merge Two Sorted Linked ListsO(n + m)
A dummy node gives the merged list a fixed start. tail points at its last node. Each step links the smaller of the two front nodes after tail and moves on. When one list ends, link the rest of the other.
- Valid ParenthesesO(n)
Push every opening bracket. A closing bracket must match the top of the stack. At the end, the stack must be empty.
- Min StackO(1)
Keep a second stack beside the first. Each push also pushes the minimum so far onto it. Popping both keeps them in step, so the top of the second stack is always the current minimum.
- Queue Using Two StacksO(n)
New values go on the in stack. To dequeue, take from the out stack; if it is empty, pour the whole in stack into it first. Pouring reverses the order, so the oldest value ends up on top.
- Circular Queue (Ring Buffer)O(1)
An array of k slots, a head index for the front, and a count. Enqueue writes at (head + count) % k; dequeue reads at head and moves head forward. The % wraps both around the end.
- LRU Cache (Hash Map + Linked List)O(1)
A hash map finds a key’s node in O(1). A doubly linked list keeps nodes in use order: most recent at the head, least recent at the tail. A hit moves the node to the head; a miss adds at the head and, if full, removes the tail.