SHUFFLE MODES Mode 1: Random Shuffle Mode 2: Backwards Sorted Mode 3: Almost Sorted(1 in 4 elements are unsorted.) Mode 4: Already Sorted Time complexity Comparison: O((n-1)(n)/2) (best, average, worst case) Writes: Best case: 0, Average: O((n-1)(n)/2) which is 2 times fast as n^2 worst: O((n-1)(n)) which is slightly faster than n^2 Space complexity O(1): It is an in-place sorting algorithm. It does not require any auxiliary array. Similarities to Selection Sort: It selects the smallest element to place in the beginning of the array. Differences to Selection Sort: No variable is used to store the value/index of the variable, instead it keeps on swapping until it finds the minimum element. Variables used: i and j: Used for selecting the elements. k: Used for drawing the position of all elements in array. tmp: Temporary variable used for swapping.
I could not get the actual Selection Sort to work, so I implemented my own variation that uses no variable to store the minimum element of the unsorted part of the array. As you will see in the visualization, the unsorted part takes the shape of the opposite of the sorted part of the array. This is very different to the shape Bubble Sort takes.