CSCD 300 Data Structures Donald Shell's Sorting Algorithm
CSCD 300 Data Structures Donald Shell's Sorting Algorithm
1
Shell Sort - Introduction
2
Shell Sort -General Description
General Theory:
Makes use of the intrinsic strengths of Insertion sort.
Insertion sort is fastest when:
The array is nearly sorted.
The array contains only a small number of data items.
Shell sort works well because:
It always deals with a small number of elements.
Elements are moved a long way through array with each
swap and this leaves it more nearly sorted.
4
Shell Sort - example
80 93 60 12 42 30 68 85 10
10 30 60 12 42 93 68 85 80
5
Shell Sort - example (2)
Resegmenting Gap = 2
10 30 60 12 42 93 68 85 80
10 12 42 30 60 85 68 93 80
6
Shell Sort - example (3)
Resegmenting Gap = 1
10 12 42 30 60 85 68 93 80
10 12 30 42 60 68 80 85 93
7
Gap Sequences for Shell Sort
8
Shell Sort - Ideal Gap Sequence
9
Shell Sort - Practical Gap Sequences
10
Shell Sort - Added Gap Sequence
11
Link to the Java program that generated the above data.
12
Shell Sort - Time Complexity
13
Shellsort - Code
14
ShellSort -Trace (gap = 4)
n: 9 i:
gap: 4 j:
n: 9 i:
gap: 2 j:
n: 9 i:
gap: 1 j: