3D Visualisation of Merge Sort using Matplotlib
Visualizing algorithms makes it easier to understand them by analyzing and comparing the number of operations that took place to compare and swap the elements. 3D visualization of algorithms is less common, for this we will use matplotlib to plot bar graphs and animate them to represent the elements of the array.
- We will generate an array with random elements.
- The algorithm will be called on that array and yield statement will be used instead of return statement for visualization purposes.
- We will yield the current states of the array after comparing and swapping. Hence the algorithm will return a generator object.
- Matplotlib animation will be used to visualize the comparing and swapping of the array.
- We will then plot the graph, which will return an object of Poly3dCollection using which further animation will be done.
For array size 20
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course