Skip to content
Aashish Bharadwaj edited this page May 26, 2020 · 11 revisions

Here is how to use the program, in depth. To learn more about how each algorithm works, see pages on the right.

Note: Big O notation generally simplifies (ie O(2n + 3) becomes O(n), as all constants are removed), however I didn't do so in the descriptions of the algorithms here to give a better picture of their exact time complexities. However this is wrong, and I will update them in the future to the correct complexities to match their respective notations.

Inputs

Input Type

How items in the array are generated.

Already Sorted

Generates an array of numbers increasing in size, starting from Smallest Number and ending at Largest Number. The generator attempts to have a balanced amount of each number based on the input size.

Reverse Order

Generates an array of numbers decreasing in size from Largest Number to Smallest Number. Balances the number of appearances of each number based on the Input Size.

Random

Generates an array of a bunch of randomized numbers in the range between Smallest Number and Largest Number.

Input Parameters

The text fields for user input. The generator will generate integers between Smallest Number and Largest Number. The number of generated items is based on the Input Size. If a non-random Input Type is selected, then the generator will try to create an equal number of each generated integer. For example, if the user inputs

Input Size = 10, Smallest Number = -2, and Largest Number = 2, Input Type = Already Sorted

then the generated array will be

-2, -2, -1, -1, 0, 0, 1, 1, 2, 2.

If the user inputs

Input Size = 6, Smallest Number = 0, and Largest Number = 12, Input Type = Reverse order

then the generated array will be

12, 10, 8, 6, 4, 2.

Input Size

The number of generated items.

Smallest Number

The lowest value integer in the generated array.

Largest Number

The highest value integer in the array.

Block Size

The number of array items in each thread. The program splits the sorting into multiple concurrent threads based on the Input Size / Block Size. At the end, the individually sorted arrays are merged via Merge Sort.

Program structure

GUI

The program uses JavaFX The alert dialog heights are calculated using a mathematical formula I created. It is a the natural log of the size of the content needed to be displayed times the square root of the content needed to be displayed plus one-fifth the height of the screen resolution. However, it has lower bound of one-fifth the screen resolution and upper bound 80% of the screen resolution. The formula is the following:

double windowHeight = Math.max((Screen.getPrimary().getVisualBounds().getHeight() / 5) + Math.sqrt(content.length()) * Math.log1p(content.length()), Screen.getPrimary().getVisualBounds().getHeight() / 5), Screen.getPrimary().getVisualBounds().getHeight() * 0.8);

Threads

There is a class that implements runnable (namely Fork) that has a switch block that calls the selected sorting method on the array. It also does most of the exception handling for the sorting functions. Threads are created based on the Input Size / block size. For example,

Input Size = 20, Block Size = 9

would create 3 threads. The first two would each sort arrays of size 9, the last would have an array of size 2 (the leftover elements).

Initiating and Completing Sorting

The Sort class is a superclass for all the sorting subclasses, and contains many commonly used methods. Also, it has the methods to generate the arrays, and start sorting the arrays. It also handles merging the sorted blocks back into the original array. It waits until _allI threads are completed before merging.

Clone this wiki locally