Data Structure Visualizations

About

A useful aid to understand complex data structures is to see them in action. We've developed interactive animations for a variety of data structures and algorithms. Our visualization tool is written in Javascript using the HTML5 canvas element, and run in just about any modern browser – including iOS devices like the iPhone and iPad, and even the web browser in the Kindle! (The frame rate is low enough in the Kindle that the visualizations aren't terribly useful, but the tree-based visualizations – BSTs and AVL Trees – seem to work well enough)

History

The code was originally developed by David Galles, University of San Francisco, in Java and then ported to Javascript in 2011. Some updates were made by Kostas Chatzikokolakis, and this current repository is maintained by Peter Ljunglöf, University of Gothenburg & Chalmers University of Technology.

Source code

All source code is available at the GitHub repository. Everything is licensed under FreeBSD, and you can use it for whatever you like.

Help

Algorithm Specific Controls

At the top of the screen (boxed in red in the above screenshot) are the algorithm specific controls -- these will change depending upon what algorithm you are visualizing. For example, in a BST (binary search tree) you can insert, delete, or find an element in the BST by entering text in the appropriate field and either pressing return or clicking the relevant button. The tree can be printed by clicking the print button. Once you give a command, the visualiztion will start, and can be controlled by the general animation controls at the bottom of the screen.

General Animation Controls

Note that it can be easy to confuse yourself by stepping forward an backwards through an animation – you can confuse the next step in the animation with the previous step, and misunderstand how the algorithm works. You may wish to only step forward when you are first delving into a particular algorithm.

Frequently asked questions

  1. Can I use these materials in my classes?
    • Certainly! We'd prefer that you just link to these pages rather than cache anything locally so that your students will get the most up-to-date version of everything. If you do use this in your class, please drop us a line to let us know about it, we're curious to see who else will find this useful.
  2. I think I've found a bug...
    • Please create an issue in the GitHub repository. Try to be specific – that is, exactly what sequence of operations lead to the undesired behavior.
  3. How are elements ordered, e.g., when inserting elements into ordered search trees?
    • Numbers are ordered numerically and strings are ordered lexicographically. Furthermore, Furthermore, we decided that all numbers are smaller than all strings.
  4. How can I get this to work on my cellphone, which has a very small screen?
    • If you change the canvas size to something that seems reasonable for your device, we will use a cookie to remember your preferred size. However, some visualizations (e.g., sorting and graphs) require that the canvas size is large, which makes them difficult to work with on a cellphone.
  5. Wait ... you are using cookies?
    • Only for remembering your preferred animation speed and canvas size. Everything will still work if you disable cookies. We aren't doing tracking of any kind.
  6. Can I use this material as a base for my own visualizations?
    • Yes! See the GitHub repository for a simple tutorial and links to the source code. If you do use the code, please leave in the copyright information at the beginning of each source file, and put a link to these pages from the page where your visualizations are located. If you create something really cool, please let us know.