Home  Writing  Games  Music  Dev  About 

Arrays

Arrays.h contains a custom Unordered Array class, exposing methods to add elements, remove elements, and other operations on elements in the array.

Also contains algorithms such as linear search, and now will add sort algorithms to it.

Linear Search O(n)

Bubble Sort O(n²)

Selection Sort O(n²)

Insertion Sort O(n²)

MergeSort O(n (log n))

Shell Sort O(n (log n)²)

Quick Sort O(n (log n))

    QuickSort()
        {
            if (start >= end) return (c) 
            index = partition() (a.n + b) (looping through the list) (T(n))
            QuickSort(start, index-1) T(n/2)
            QuickSort(index+1, end) T(n/2)
        }

Median of Three

Randomized Partioning

Partitioning O(n)

Radix Sort O(n (log n))

Put elements into buckets/container according to some patter, then take them back from buckets into the original container. After potentially multiple passes of doing so, data would be ordered according to the final putting back of elements from the organising containers. No comparison of value by value goes on.

Heap Sort O (n log n)

Intro Sort

Cyclic Sort

As seen in shufflestringCyclicSort: - Loop through array, but stay on current i until indices[i] matches with i - Do swaps here until the above is true - Then move to next i until length of array covered. - Usually first few i's enough to sort array.

Ordered Arrays

orderedarray.h contains custom Ordered Array class. Is already sorted through a push method, which uses a form of insertion sort (also modified to binary search insertion sort) to keep the array sorted as new elements are added.

It has binary search available instead of linear search, which reduces complexity from O(n) to O(log n).

And I'm sure probably some other functions etc for the array class.

Binary Search O(log n)

Arrays and STL Vectors

    SomeClass someArray[100]; // calls a 100 constructors for 100 objects.
    
        vector<SomeClass> someVec;
        someVec.reserve(100); // no constructors are executed to store.