Visualizing Sorting Algorithms
This interactive visualization compares five sorting algorithms—merge sort, insertion sort, selection sort, bubble sort, and bogosort—by animating the rearrangement of vertical bars on an SVG canvas. Buttons let the user trigger each sort, stop it mid-process, or reshuffle the initial data. The code uses D3 v4 to render and transition the bar rectangles and value labels, with the current step count displayed in a counter. Sorted or actively tested elements are highlighted in red via CSS classes, while color changes and positions update through `d3.select` and `.transition()` calls at a duration scaled to the dataset size.
AI-generated descriptionJavaScript and D3.js have their own means for sorting and one may never need to use traditional sorting algorithms when developing in JavaScript. So I made this for comparing sorting algorithms in an environment that is more familiar to me.
It's a bit of an off-shoot of the Mergesort series I did here: <a href="http://bl.ocks.org/alexmacy/d6f48eb15d4608c3a71b7681309ebf8c">Mergesort w/ color</a> & <a href="http://bl.ocks.org/alexmacy/9f109c383f8ed21f5f610cb21113ca68">Mergesort animation</a>. I left Mergesort out here because it doesn't work very well with the way I wanted to visualize these. Instead, I used insertion sort, selection sort, bubble sort, and bogosort just for fun.
- Update 10/9/16: Added Mergesort.
forked from <a href='http://bl.ocks.org/alexmacy/'>alexmacy</a>'s block: <a href='http://bl.ocks.org/alexmacy/770f14e11594623320db1270361331dc'>Visualizing Sorting Algorithms</a>
forked from <a href='http://bl.ocks.org/anonymous/'>anonymous</a>'s block: <a href='http://bl.ocks.org/anonymous/9fac1bf510409fe0c8e4c73ffa652955'>Visualizing Sorting Algorithms</a>
forked from <a href='http://bl.ocks.org/anonymous/'>anonymous</a>'s block: <a href='http://bl.ocks.org/anonymous/472d81fe469764f16b9d83ab4dc4f20e'>Visualizing Sorting Algorithms</a>