Interactive · Data Structures

Data Structure Visualizer

See how the fundamental data structures behave. Push and pop a stack, enqueue and dequeue a queue, or insert and search a binary search tree — each operation animates so you can watch which end it touches and which path it walks.

Structure
Value
Operations

Three structures, three access rules

More algorithm visualizers

Data structures are one half of the picture; the algorithms that run on them are the other. Watch six sorts race on a bar chart in the Sorting Algorithm Visualizer, see BFS, Dijkstra and A* in the Pathfinding Visualizer, or step through minimax and expectimax in the Game AI Visualizer. Everything runs client-side; nothing you enter leaves your browser.

Frequently asked questions

What is the difference between a stack and a queue?

A stack is LIFO — last in, first out: you push items onto the top and pop them off the same end, like a stack of plates. A queue is FIFO — first in, first out: you enqueue at the rear and dequeue from the front, like a line of people. Both push/pop and enqueue/dequeue run in O(1) constant time. The visualizer shows the top of the stack and the front and rear of the queue so you can see which end each operation touches.

How does a binary search tree work?

A binary search tree keeps every value smaller than a node in its left subtree and every larger value in its right subtree. To insert or search, you start at the root and go left or right by comparing values, so you only ever follow one path down the tree — about log n steps for a balanced tree. Press Insert or Search in the visualizer and watch the highlighted path walk down the tree. An in-order traversal of a BST always yields the values in sorted order.

What is the time complexity of these operations?

Stack push and pop and queue enqueue and dequeue are all O(1) — constant time, independent of how many items are stored. Binary search tree insert and search are O(log n) on average when the tree is reasonably balanced, but degrade to O(n) in the worst case if values are inserted in sorted order, which makes the tree a straight line. The status line reports how many comparisons each operation took.

Where are these data structures used?

Stacks power function call stacks, undo/redo and expression parsing; queues drive task scheduling, buffering and breadth-first search; binary search trees (and their balanced variants) back ordered maps and sets in many standard libraries. They are the building blocks behind most algorithms, which is why they are taught first. This tool runs the textbook versions in the browser so you can see each operation directly.