Practice algorithms visually

DSA Lab

A code visualizer for understanding what an algorithm is doing, one state at a time. Paste your code, run the trace, and step through every comparison, swap, and call.

Bubble sort
1/17
1const arr = [...input.array];
2 
3for (let i = 0; i < arr.length - 1; i++) {
4 for (let j = 0; j < arr.length - i - 1; j++) {
5 if (arr[j] > arr[j + 1]) {
6 [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
7 }
8 }
9}
10 
11return arr;
5
3
8
1
2

Copy the input array

Built for interview practice

Make the invisible parts of code visible.

Trace each move

Run code in a focused sandbox and move through every useful state at your own pace.

See the structures

Arrays, hash maps, windows, stacks, queues, graphs, and recursive call stacks stay visible.

Use your own code

Paste JavaScript or TypeScript, add JSON input, and get an inferred trace without writing custom visualization code.

Keep a practice library

Sign in to save named solutions by topic, then return to them whenever you want to practice.

Structured practice

Work through interview questions, one by one.

Three question banks — Top Interview 150, NeetCode Roadmap, and Sorting Algorithms — with curated solutions in 5 languages, progress tracking, and one-click visualization.

3 of 7 solved

43%

Search by title, number, or tag…/
2/4
  1. 1Two Sum
    Easy
    solved
  2. 49Group Anagrams
    Medium
    solved
  3. 128Longest Consecutive Sequence
    Medium
    Visualize
  4. 238Product of Array Except Self
    Medium
    Visualize
1/3

j / k navigate · Space toggle · / search

See it in action

A trace, one step at a time.

Five live demos, one per family — sorting, searching, trees, hashing, and recursion. Each one plays the real visualizer: bubble sort swaps values into place, binary search narrows its window, Invert Binary Tree mirrors a tree, Two Sum builds a hash map, and fibonacci grows and unwinds its recursive call stack.

Step 1 / 17
1const arr = [...input.array];
2
3for (let i = 0; i < arr.length - 1; i++) {
4 for (let j = 0; j < arr.length - i - 1; j++) {
5 if (arr[j] > arr[j + 1]) {
6 [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
7 }
8 }
9}
10
11return arr;
5
0
3
1
8
2
1
3
2
4

Copy the input array

Step 1 / 7
1function binarySearch(arr, target) {
2 let lo = 0, hi = arr.length - 1;
3 while (lo <= hi) {
4 const mid = Math.floor((lo + hi) / 2);
5 if (arr[mid] === target) return mid;
6 if (arr[mid] < target) lo = mid + 1;
7 else hi = mid - 1;
8 }
9 return -1;
10}
11
12return binarySearch([1, 3, 5, 7, 9, 11, 13], 9);
1
0
3
1
5
2
7
3
9
4
11
5
13
6
lo 0hi 6

lo = 0, hi = 6 — the search space is the whole array

Step 1 / 6
1function invertTree(root) {
2 if (!root) return null;
3 [root.left, root.right] = [root.right, root.left];
4 invertTree(root.left);
5 invertTree(root.right);
6 return root;
7}
8
9return invertTree(tree);
4271369

Start at the root — invertTree(4)

Step 1 / 7
1function twoSum(nums, target) {
2 const seen = new Map();
3 for (let i = 0; i < nums.length; i++) {
4 const complement = target - nums[i];
5 if (seen.has(complement)) return [seen.get(complement), i];
6 seen.set(nums[i], i);
7 }
8 return [];
9}
10
11return twoSum([2, 7, 11, 15], 9);
20
71
112
153
seen map
— empty —

seen = {} — no numbers remembered yet

Step 1 / 43
1function fib(n) {
2 if (n <= 1) return n;
3 return fib(n - 1) + fib(n - 2);
4}
5
6return fib(5);
Recursive call stack
— empty —

Start the trace: call fib(5)

From pasted code to a useful explanation.

  1. 01

    Paste an algorithm and provide JSON input.

  2. 02

    Run the trace to infer changes in variables and data structures.

  3. 03

    Step forward, back, or play the animation while the active line stays in focus.

Watch it in 25 seconds — with narration

You can read code. Now watch it think.

Built to help you learn

DSA Lab exists for one reason: to help students and learners actually understand algorithms — by watching every step, not just memorizing the answer. It's free, and it's made with that goal in mind.

One honest note: visualizations are generated from real code traces, and we check them against known answers — but no tool is perfect. If a step ever looks wrong or confusing, it probably is. Tell us and we'll fix it.