mirror of
https://gitlab.com/magicalsoup/Highschool.git
synced 2025-01-23 16:11:46 -05:00
Update Shellsort List.md
This commit is contained in:
parent
3e06aaa403
commit
2a6d9b2977
@ -31,7 +31,7 @@ The space complexity of shell sort will always be **O(1)** as it does not create
|
||||
|$`4^k+3\times2^{k-1}+1`$|$`1, 8, 23, 77, 281`$|$`O(N^\frac{4}{3})`$|Sedgewick - 1982|
|
||||
|
||||
## Sample Program
|
||||
```
|
||||
```java
|
||||
public static void shellSort(int arr[]) // Method Header
|
||||
{
|
||||
for(int gap = arr.length / 2; gap > 0; gap /= 2){ // Loop through the length of the gap sequences
|
||||
@ -53,4 +53,15 @@ public static void shellSort(int arr[]) // Method Header
|
||||
- The gap sequence would be h<sub>1</sub> and h<sub>n+1</sub> = 3h<sub>n</sub>+1
|
||||
- For 100 elements, shell's original gap seuqence will make 170 comparisons but the Enhanced Shell Sort will make 85 comparisons
|
||||
|
||||
## Testing
|
||||
`10 Elements: 100, 37, 12, 86, 2, 127, 62, 14, 3, 9` <br/>
|
||||
**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
|
||||
|
||||
`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/>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user