Blog

Algorithm Visualization Tools: VisuAlgo, Python Tutor and More

If you want to see an algorithm run step by step, use VisuAlgo for data structures and classic algorithms, Python Tutor to watch your own code execute line by line, and the USFCA Data Structure Visualizations for quick, no-frills animations. Algorithm Visualizer lets you see code-driven visualizations of many algorithms. VisuAlgo and Python Tutor state on their sites that they are free; check the others yourself before relying on them.

A visualization helps only if you use it actively. This post covers what each tool is good at, a workflow that makes the animation stick, and what to do when no ready-made visualization exists: print your own.

The tools

VisuAlgo

VisuAlgo (visualgo.net) was created by Associate Professor Steven Halim at the National University of Singapore, together with Dr Felix Halim, and has been growing since 2011. It covers a wide range of topics: sorting, linked lists, heaps, hash tables, binary search trees, graph traversal, shortest paths, union-find, segment and Fenwick trees, recursion, network flow and more. It is free. Each module has an e-Lecture mode that explains the animation in steps, lets you enter your own input for many structures, and ends with an online quiz of randomly generated questions that are graded automatically.

Best for: students who want the textbook algorithm animated with explanation, and for checking an answer by entering your own input.

Python Tutor

Python Tutor (pythontutor.com) is different: it does not animate a named algorithm. You paste your own code and step through it, seeing variables, objects, pointers and stack frames drawn as boxes and arrows. Its homepage lists Python, Java, C, C++ and JavaScript, and says the tool is meant to stay free for everyone.

Best for: recursion (watch the stack frames grow and unwind), linked lists (see the pointers), and any bug where you do not know which variable holds what.

Data Structure Visualizations (USFCA)

David Galles at the University of San Francisco maintains a long list of animations at cs.usfca.edu/~galles/visualization. It includes stacks and queues, binary search and several balanced trees (AVL, red-black, splay, B-trees), hash tables, heaps, the usual sorts, BFS, DFS, Dijkstra, Prim, Kruskal, and some dynamic programming examples. The page design is plain and dated, and the animations are fast to use: type a value, press insert.

Best for: watching a tree rotate or a heap sift, and anything you want to check quickly.

Algorithm Visualizer

Algorithm Visualizer (algorithm-visualizer.org) is an open-source project that pairs code with a visualization: the code calls small tracer libraries, and the page draws what those commands describe. Because the visualization comes from code, you can read and edit it.

Best for: seeing how an algorithm is built from code, and for people who want to contribute a visualization.

Pathfinding Visualizer

Clement Mihailescu’s open-source Pathfinding Visualizer, published through GitHub Pages, lets you draw walls on a grid and watch Dijkstra, A*, greedy best-first search, BFS and DFS find a path. It is a good way to see why BFS finds shortest paths on an unweighted grid and DFS does not.

For a longer list that includes sorting and tree tools, see our other post, the best tools for visualizing algorithms and data structures.

Which tool for which problem

You want to understand Use
Why quicksort partitions the way it does VisuAlgo or USFCA
What your recursive function is doing Python Tutor
How a linked list reversal moves pointers Python Tutor
How a balanced tree rotates on insert VisuAlgo or USFCA
BFS versus DFS on a grid Pathfinding Visualizer, or VisuAlgo graph traversal
A bug in your own solution Python Tutor, or your IDE’s debugger

A workflow that works

  1. Read the idea first. One paragraph or one lesson. If you watch cold, you see motion without knowing what to look for.
  2. Predict, then step. Before each step, say what will happen next: which pointer moves, which element is swapped. Check against the animation. Wrong predictions are where you learn.
  3. Change the input. Try the already-sorted array, the reverse-sorted one, duplicates, one element, empty. Edge cases show behavior that a typical input hides, such as quicksort’s worst case.
  4. Write it without the tool. Close the tab and implement the algorithm from memory. Where you get stuck is what you did not understand.
  5. Trace your own code. Run your implementation in Python Tutor or a debugger and compare its states with the animation.

When there is no visualization: print one

Many interview problems have no ready-made animation. You can build a text trace in a few lines, and it doubles as a debugging tool. Here is binary search that prints the search window at each step:

def binary_search_trace(nums, target):
    lo, hi = 0, len(nums) - 1
    while lo <= hi:
        mid = (lo + hi) // 2
        cells = []
        for i, v in enumerate(nums):
            if i == mid:
                cells.append(f"[{v}]")
            elif lo <= i <= hi:
                cells.append(f" {v} ")
            else:
                cells.append(" . ")
        print(f"lo={lo} hi={hi} mid={mid} ", "".join(cells))
        if nums[mid] == target:
            return mid
        if nums[mid] < target:
            lo = mid + 1
        else:
            hi = mid - 1
    return -1

print(binary_search_trace([2, 5, 8, 12, 16, 23, 38, 56, 72, 91], 23))
print(binary_search_trace([2, 5, 8, 12, 16, 23, 38, 56, 72, 91], 7))
lo=0 hi=9 mid=4   2  5  8  12 [16] 23  38  56  72  91 
lo=5 hi=9 mid=7   .  .  .  .  .  23  38 [56] 72  91 
lo=5 hi=6 mid=5   .  .  .  .  . [23] 38  .  .  . 
5
lo=0 hi=9 mid=4   2  5  8  12 [16] 23  38  56  72  91 
lo=0 hi=3 mid=1   2 [5] 8  12  .  .  .  .  .  . 
lo=2 hi=3 mid=2   .  . [8] 12  .  .  .  .  .  . 
-1

Each line shows the window still in play and the middle element being compared. For the search that fails (target 7), the window shrinks until it is empty, which is exactly what the loop condition lo <= hi checks.

Limits of visualizations

  • They hide scale. An animation with 10 elements does not show why O(n^2) is unusable at a million. Reason about complexity separately, or time your code on large inputs.
  • Watching feels like understanding. You can follow every frame and still be unable to write the code. Step 4 of the workflow is there for that reason.
  • Simplified pictures. An animation may leave out details such as how a hash table resizes or what happens on a collision. Check the details in code.
  • No interview substitute. In an interview you draw on a whiteboard or type. Practice sketching the state yourself; our post on recursion trees and visualization shows how to do it for recursion.

Combine it with practice

Pick an algorithm, watch it once, then solve problems that use it until you can explain it. For binary search, that means problems such as Binary Search; for shortest paths, Dijkstra’s Algorithm. The lessons on AlgoCademy are step-by-step with tests, which is a different thing from an animation: the animation shows the idea, and the problem checks that you can use it.

A lesson in AlgoCademy: the step to write, a picture of what it does, the line written in the editor, and the check: Step 2 passed

Before you go

Start thinking like a software engineer.

Learn to code and solve interview problems, one small, checked step at a time.

Free, no card needed. Or look around first

By continuing you agree to the Terms of Service and Privacy Policy.