1
0
mirror of https://gitlab.com/magicalsoup/Highschool.git synced 2025-01-23 08:01:46 -05:00

Update Shellsort List.md

This commit is contained in:
Pete ._. Mango 2019-11-07 21:40:25 +00:00
parent 1c9c5b9e66
commit 98aab86a5e

View File

@ -12,7 +12,7 @@
**Worst Case:** $`O(N^2)`$
## Space Complexity:
The space complexity of shell sort will always be **O(1)** as it does not create another array
The space complexity of shell sort will always be __O(1)__ as it does not create another array
## Pros & Cons:
|Pros|Cons|
@ -47,6 +47,19 @@ public static void shellSort(int arr[]) // Method Header
```
## Comparison to Other Sorting Algorithms:
### Shell vs Insertion
Shell sort can be seen as an improvement to insertion sort as it uses a variety of gap sequences and moves out of place elements into their correct positions faster whereas insertion sort will check each one by one. However, if the array is partially or nearly sorted, then insertion would still be the better option. Like selection sort, shell sort should be used for larger data sets.
### Shell vs Selection
Both insertion and shell sort can be used when the memory restraint is super tight and does not allow for auxillary memory. However, shell sort has a best case of $`O(NLogN)`$ while selection sort has a best time complexity of $`O(N^2)`$. For larger data sets, shell sort would obviously be more appealing than selection.
### Shell vs Quick
Shell sort and quick sort does not serve the same purpose, but many people tends to use quicksort as it is known as the "Queen of All Sorts" for its ability to sort randomized list in a short amount of time. However, shell sort is more favorable with strict space complexity as quick sort requires $`O(NLogN)`$ auxillary space complexity.
### Shell vs Merge
Merge sort is often regarded as one of the best sorting algorithms with consistent $`O(NLogN)`$ time complexity. However, like quick sort, it requires $`O(2N)`$ memory, which sometimes will result in MLE (Memory Limit Exceeded). For larger data sets, merge sort would, most of the time, be the better sorting algorithm.
## Enhanced Shell Sort
- A method to calculate the gap sequence and can decrease the number of comparisons by up to 60%
- Published by Basit Shahzad and Muhammad Tanvir Afzal from the World Academy of Science
@ -55,16 +68,16 @@ public static void shellSort(int arr[]) // Method Header
## Testing
`10 Elements: 100, 37, 12, 86, 2, 127, 62, 14, 3, 9` <br/>
**Shell Sort:** 30 <br/>
**Enhanced Shell Sort:** 12
Shell Sort: *30* <br/>
Enhanced Shell Sort: *12*
`25 Elements: 100, 37, 12, 86, 2, 127, 62, 14, 3, 9, 30, 14, 90, 1, 20, 30, 74, 48, 37, 40, 7, 101, 200` <br/>
**Shell Sort:** 47 <br/>
**Ehanced Shell Sort:** 31
Shell Sort: *47* <br/>
Ehanced Shell Sort: *31*
`35 Elements: 1,2,23,12,25,7,9,5,36,1,100,37,12,86,2,127,62,14,3,9,30,14, 90,1,20,30,74,48,37,40,7,101,200,4,9 ` <br/>
**Shell Sort:** 202
**Enhanced Shell Sort:** 105
Shell Sort: *202* <br/>
Enhanced Shell Sort: *105*
## Number of Comparisons to Array Size Chart
![alt text](https://i.imgur.com/SNfzwpU.png)