This project provides a comprehensive visualization of four fundamental sorting algorithms: Insertion Sort, Merge Sort, Heap Sort, and Quick Sort. The visualization is implemented using Java, making it an educational tool for understanding how these algorithms work.
- Insertion Sort Visualization: Demonstrates the process of building a sorted array one element at a time.
- Quick Sort Visualization: Shows the divide-and-conquer approach to sorting by partitioning arrays.
- Heap Sort Visualization: Illustrates the process of converting an array into a heap and sorting it.
- Merge Sort Visualization: Displays the process of dividing arrays into smaller sub-arrays and merging them back in sorted order.
1. Overall Structure:
- The main class Sort6 and its associated helper classes (Arr, Arr_Box, GUI_Display_Arr) form the core of the application.
- Sorting algorithms such as Insertion Sort, Merge Sort, Quick Sort, and Heap Sort are implemented and visualized through this GUI.
2.Visualization Setup:
- Java's Swing framework is used for GUI components (JFrame, JPanel, JButton, etc.).
- Components are organized into panels (input, update_btn, shuffle_btn, output1, output2, etc.) to manage user input, algorithm execution, and displaying results.
3.Algorithm Implementation:
- Each sorting algorithm (insertion(), merge(), quick(), heap()) is encapsulated within methods that perform the sorting logic and update the GUI accordingly.
- For instance, Heap Sort (heap()) initializes a max heap, performs heapification, and repeatedly extracts the maximum element to achieve sorting.
4.GUI Interaction:
- The GUI_Display_Arr class manages the visualization of arrays and tree structures representing sorting algorithms.
- Methods like addArr(), addTree(), warpup(), etc., handle updating the GUI with arrays, tree structures, and text descriptions of algorithm steps.
5.User Controls:
- Buttons (start, stop, previous, next) control the flow of visualization, allowing users to start, stop, and navigate through algorithm steps.
- Input fields (input) accept user-defined arrays for sorting, which are then visualized and processed by the sorting algorithms.
6.Execution Flow:
- When the program starts, users input an array, choose a sorting algorithm, and initiate sorting.
- The GUI updates dynamically to show the current state of the array and algorithm execution step-by-step.
sorting_algorithm.1.mp4
-
Install Java Development Kit (JDK)
-
Install Visual Studio Code
-
Set Environmental Variable for Java in the system.
(i)Set the Variable name as 'JAVA_HOME'(ii)Set the Variable value to the path of your JDK installation directory.(iii)Under System Variables ->Path ->Edit ->New -> Add '%JAVA_HOME%\bin' -
Verify Installation
In Command Prompt(cmd)
echo %JAVA_HOME%Then
java --version -
Install VS Code Extensions
Search for "Java Extension Pack" and install it.
-
Clone this repository
javac Sort6.java
java Sort6



