Developer

Sorting Visual

Algorithm visualization focusing on complexity analysis and visual comparisons.

Timeframe
November 2020
Stack
Java · Algorithms · Data Visualization
  • Complexity analysis visualization
  • Side-by-side algorithm comparison
  • Performance metrics and timing

Project Overview

A text-based sorting algorithm comparison tool that outputs the complexity and time taken for various sorting algorithms on randomly generated arrays of user-inputted sizes. This project was implemented in Java and was a collaborative effort where each team member worked on different sorting algorithms.

The sorting algorithms included in this project are: Bogo Sort, Bubble Sort, Selection Sort, Insertion Sort, Quick Sort, Merge Sort, and Heap Sort.

Sorting Visual

Implementation

The implementation was relatively straightforward. Each team member was assigned one or two sorting algorithms, and the program would output the complexity and execution time for a randomly generated array at a user-inputted size in a text-based format.

For the quicksort implementation, I used a recursive method following the standard quicksort algorithm steps. The main code was built with ArrayLists, so there was no need to return the sorted value as the parameter was passed by reference—meaning the value passed as the parameter would change when the value in the method was changed.

Here's the QuickSort implementation:

public static void quickSort(ArrayList<Integer> sortMe) {
    quickSort(sortMe, 0, sortMe.size()-1);
}

public static void quickSort(ArrayList<Integer> sortMe, int low, int high) {
    if (low < high+1) {
        int p = partition(sortMe, low, high);
        quickSort(sortMe, low, p-1);
        quickSort(sortMe, p+1, high);
    }
}

public static int partition(ArrayList<Integer> sortMe, int low, int high){
    int split = low + 1;
    for (int i = split; i <= high; i++) {
        if (sortMe.get(i) < sortMe.get(low)) {
            swap(sortMe, i, split++);
        }
    }
    swap(sortMe, low, split-1);
    return split-1;
}

Conclusion

This project was not super difficult, and I actually did not do it by myself. I implemented the quick sort and helped integrate everything together, but my classmates worked on some of the other sorting algorithms. This was an exercise to understand the algorithms and see how each one compares to another. The project was coded in Java.