Visualizing sorting algorithms in python (tutorial): Part 2

preview_player
Показать описание
This video series shows how the Python programming language can be used to generate movies that visualize the steps taken by algorithms

In particular this multi-part series will look at generating the array accesses taken by two sorting algorithms, the insertion sort and quick sort. It will include an audio generation part that will allow the user to "hear" the sound of sorting.

This video is aimed at undergraduates or anyone interested in STEM subjects or python.

Part1:
Creating a plot of the unsorted and sorted data using both the insertion sort and quick sort

Part2:

Creating a class that tracks the state of the data during the sorting algorithms. We then generate an animation of the sorting algorithms and create a movie from the animation (using FFMPEG)

Part3:
Generating smooth sounding audio that represents the data been accessed by the algorithms and then combining this sound with the previously created movie!

See the following links for visualizations of sorting algorithms:

Рекомендации по теме
Комментарии
Автор

This is awesome man i am going to use it as a basis for a portfolio project but try to add on functionality for comparing the algorithms by putting this in a web app. Do you think Flask would be easiest or would it be easier to use something like React in conjunction with this file? It is my first time using python, I am mainly a C++/ JS developer previously.

SomeDSquares
Автор

Hey there, My code doesnt seem to work as yours is at 14:00 timestamp.
My code gives following error :-
ani = FuncAnimation(fig, update, frames=range(len(arr.full_copies)),

AttributeError: 'numpy.ndarray' object has no attribute 'full_copies'

Please help

aryanrai
Автор

What is the full copies? What do they mean?

python.programmer
Автор

Does anyone know why I can't see the final graph after the sort visualization, only an empty plt is left

lukasarrow
Автор

Good demo! I had a couple of questions though: why is it that even though your update function requires "frame" as an input, you can call it without any inputs or parentheses? Is it not a function?
Also, I tried to define the update function earlier on in my code (right after the class definition): def update(arr, frame, container) and passed in the frame and container. But that threw a TypeError in update
for (rectangle, height) in zip(container.patches, arr.full_copies[frame])
TypeError: only integer scalar arrays can be converted to a scalar index

I thought that placing the function definition at the top to avoid using global variables would be the way to go but don't understand how this could be done. Cheers!

aarjavkhara
Автор

Hey there, My code doesnt seem to work as yours is at 14:00 timestamp. My code just gives me an unsorted list graph but does not sort it. I was wondering if u could help me with it

brown_canadian
Автор

You could do better with the audio...Great topic for tutorial though 👍

saurabhkashyap