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. For this we will use matplotlib, to plot bar graphs 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 a 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.
- The array will be stored in a matplotlib bar container object (‘bar_rects’), where the size of each bar will be equal to the corresponding value of the element in the array.
- The inbuilt FuncAnimation method of matplotlib animation will pass the container and generator objects to the function used to create animation. Each frame of the animation corresponds to a single iteration of the generator.
- The animation function is repeatedly called will set the height of the rectangle equal to the value of the elements.
Below is the implementation of the above approach.
- Sorting Algorithm Visualization : Merge Sort
- Insertion Sort Visualization using Matplotlib in Python
- Visualization of Quick sort using Matplotlib
- Merge Sort with O(1) extra space merge and O(n lg n) time
- COVID-19 Data Visualization using matplotlib in Python
- 3D Visualisation of Merge Sort using Matplotlib
- Sorting Algorithm Visualization : Quick Sort
- Sorting algorithm visualization : Insertion Sort
- Sorting algorithm visualization : Heap Sort
- Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists?
- Quick Sort vs Merge Sort
- Merge Sort vs. Insertion Sort
- Merge operations using STL in C++ | merge(), includes(), set_union(), set_intersection(), set_difference(), ., inplace_merge,
- Python - Data visualization using Bokeh
- Data Visualization Using Chartjs and Django
- Interactive visualization of data using Bokeh
- Animated Data Visualization using Plotly Express
- Data Visualization using Turicreate in Python
- Binary Search Visualization using Pygame in Python
- Union and Intersection of two linked lists | Set-2 (Using Merge Sort)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.