Visualization and Comparison of Sorting Algorithms

Viktor Bohush · 1.1M views · 2014 · 4:26

Open on YouTube

Algorithms & data structuresData visualization & information designdemo

Why Stack Overflow recommends it

Stack Overflow users link it when they want a quick visual of how different sorting algorithms behave and how their speeds compare, for example when explaining bubble sort's inefficiency or building their own sorting visualizers.

Recommended by 2 people across 2 different months, 2015 to 2021.

What it is

A 4.5 minute animated visualization comparing nine sorting algorithms (selection, shell, insertion, merge, quick, heap, bubble, comb, cocktail) side by side. Each runs on four input types: random, few unique, reversed and almost sorted. The source code is published on GitHub.

What people said

Recommends Timmetje · 2016-12 · Stack Overflow · on “How does JavaScript's sort (compareFunction) work?”

Visualizing different algorithms makes a simple understanding on how they loop they array and what happens. Look at this for example: [LINK] Also benchmarking is cool visualized: [this video]

Recommends Florian Fasmeyer · 2021-03 · Stack Overflow · on “Python Compare sorting for different data types”

The type of data does not impact the sorting speed, at least not directly. What " may " change with the datatype is the time to access or modify the data. But even then it is situational as there is no "one best datatype". Some data is mutable. It means that it can be modified, such as lists. my_list = [1,2,3,4] my_list[2] = 6 # Prints: [1,2,6,4] print(my_list) But other types are immutable, which means they can not be changed. This is the case for tuples. my_tuple = (1,2,3,4) #Throws: TypeError: 'tuple' object does not support item assignment my_tuple[2] = 6 print(my_tuple) So to modify an immutable you must copy everything and put your new numbers in memory (NB. Immutables are great in man

Cites Pshemo · 2015-01 · Stack Overflow · on “different ways of sorting ArrayList of of HashMap<String, String>”

@Joe bubble sorting is very far away from effective one (see example video [this video] ) but it is indeed simple one. If you are looking for effective solution use default `sort` method which uses effective algorithms (currently in most cases slightly optimized version of merge-sort is used), your only job would be provide code which should decide if two elements should be swapped (Comparator), so you don't have to implement sorting algorithm, which main job is to pick *which elements should be compared* ( and swapped if they are in wrong positions).

Cites Andris Jefimovs · 2021-01 · Stack Overflow · on “Synchronize function execution (sorting algorithms)”

I have 4 sorting algorithms which I want to visualize. I want to make them run at the same time. Should I write functions like bubbleSortStep instead of just bubbleSort to call it every second for example and execute one step. For example like this: setInterval(() => { bubbleSortStep() insertionSortStep() quicksortStep() }, 1000) Or is it going to work fine if I create the sorting functions the normal way and add an interval to each of them like: bubbleSort() { setInterval(() => { // sorting... }, 1000) } ...same for other three, and call them afterwards. bubblesort() insertionSort() quicksort() The idea is coming from YouTube videos like this [this video] where the colors change all at once.

Cites atabulog-DSM · 2021-05 · Stack Overflow · on “How do you arrange 3D points in a clockwise order in C?”

It sounds like you are dealing with a 2D data set instead of a 3D set. This should simplify your answer greatly. I believe you will need to calculate the mean distance between points to find what points are closest and should be "next" to one another. This is a case where optimization is critical. A good breadth of general sorting algorithms can be seen here: [this video] I would research and see what works best for your application.