Sorting algorithms are the basic algorithms for beginners who want to learn computer science or programming. But sometimes you will get confused about how these algorithms work. Thus, there are plenty of visualizations of these sorting algorithms for beginners. But there are no visualization methods based on LEDs. Then I decided to implement one with Arduino and a LED strip.
To implement a sorting algorithm, firstly you need an unsorted array. So I used a built-in random() function to generate an array filled with elements between (0, 30). And they are unsorted. To visualize those numbers, I created a setColor() function to convert a certain number to a RGB array. Then use the RGB array to set the color of a specified LED.
As you can see, color red represents smaller values. During the sorting process, the red LEDs moved up like bubbles in water. That's why this sorting algorithm is called bubble sort.
Quick sort is much more efficient than classical bubble sort.