VOOZH about

URL: https://www.geeksforgeeks.org/python/3d-visualisation-of-merge-sort-using-matplotlib/

⇱ 3D Visualisation of Merge Sort using Matplotlib - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

3D Visualisation of Merge Sort using Matplotlib

Last Updated : 19 Jan, 2022

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.

Approach :

  1. We will generate an array with random elements.
  2. The algorithm will be called on that array and yield statement will be used instead of return statement for visualization purposes.
  3. We will yield the current states of the array after comparing and swapping. Hence the algorithm will return a generator object.
  4. Matplotlib animation will be used to visualize the comparing and swapping of the array.
  5. We will then plot the graph, which will return an object of Poly3dCollection using which further animation will be done.

Output : 
 

For array size 20


 


 

Comment
Article Tags: