This repository contains a Python script that visualizes the step-by-step process of various sorting algorithms using matplotlib. The script dynamically generates bar charts to represent the state of the array at each step of the sorting process, creating a simple animation.
- Visualize the sorting process for different algorithms.
- Command-line interface to choose the algorithm.
- Supports:
- Insertion Sort
- Merge Sort
- Radix Sort
The visualize.py script works in conjunction with pre-compiled executable files for each sorting algorithm (insertion.exe, merge.exe, radix.exe).
- When you run the script, it prompts you to select a sorting algorithm.
- Based on your choice, it executes the corresponding compiled program (e.g.,
./insertion.exe). - The executable performs the sort and writes each step of the process to a
steps.csvfile. Each row in the CSV contains a title for the step and the state of the array. - The Python script then reads
steps.csvusingpandas. - It iterates through each step (row) and generates a
matplotlibbar plot to display the array's state, pausing between plots to create a visual animation.
- Python 3
pandasmatplotlib- Pre-compiled executables for the sorting algorithms (
insertion.exe,merge.exe,radix.exe) must be present in the root directory of the repository. These executables are responsible for generating thesteps.csvfile.
-
Clone the repository:
git clone https://github.com/Krushnakant-08/Visualization_Of_Sorting.git cd Visualization_Of_Sorting -
Install the required Python packages:
pip install -r requirements.txt
Alternatively, you can install them manually:
pip install pandas matplotlib
-
Ensure the compiled executables for the sorting algorithms (
insertion.exe,merge.exe,radix.exe) are in the same directory asvisualize.py. -
Run the visualization script from your terminal:
python visualize.py
-
You will be prompted to choose an algorithm:
💡 Choose a sorting algorithm to visualize: 1. Insertion Sort 2. Merge Sort 3. Radix Sort 4. Exit Enter option (1/2/3): -
Enter the number corresponding to the algorithm you wish to see. A
matplotlibwindow will open and display the visualization.