Skip to content

Commit d2a1b16

Browse files
authored
Merge pull request deutranium#86 from pandeyxamit/shell-sort
Added Readme for Shell Sort.
2 parents 40c3b6d + 344c172 commit d2a1b16

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

sortingAlgo/ShellSort/Readme.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Shell Sort
2+
Shell sort is an algorithm that first sorts the elements far apart from each other and successively reduces the interval between the elements to be sorted. It is a generalized version of insertion sort.
3+
4+
In shell sort, elements at a specific interval are sorted. The interval between the elements is gradually decreased based on the sequence used. The performance of the shell sort depends on the type of sequence used for a given input array.
5+
6+
shellSort(array, size)
7+
for interval i <- size/2n down to 1
8+
for each interval "i" in array
9+
sort all the elements at interval "i"
10+
end shellSort
11+
## Complexity
12+
Shell sort is an unstable sorting algorithm because this algorithm does not examine the elements lying in between the intervals.
13+
### Time Complexities:
14+
* #### Worst Case Complexity: less than or equal to O(n<sup>2</sup>)
15+
* #### Best Case Complexities: O(n*log n)
16+
When the array is already sorted, the total number of comparisons for each interval (or increment) is equal to the size of the array.
17+
* #### Average Case Complexity: O(n*log n)
18+
It occurs when the elements of the array are in jumbled order (neither ascending nor descending).
19+
20+
### Space Complexity:
21+
The space complexity for shell sort is **O(1)**
22+
### Shell Sort Applications:
23+
Shell sort is used when
24+
1. calling a stack is overhead.
25+
2. recursion exceeds a limit.
26+
3. Insertion sort does not perform well when the close elements are far apart. Shell sort helps in reducing the distance between the close elements. Thus, there will be less number of swappings to be performed.
27+
28+
### Instruction for Running code:
29+
30+
- Python
31+
```
32+
python3 ShellSort.py
33+
```

0 commit comments

Comments
 (0)