2. Shell Sort
Founded by Donald Shell in 1959
1st algorithm to break the quadratic time barrier
a highly efficient sorting algorithm
known as diminishing increment sort
Generalization of insertion short
3. How does Shell Sort Works?
works by comparing elements that are distant rather than
adjacent elements in an array or list where adjacent elements are
compared
uses increment sequence
makes multiple passes through a list
improves on the efficiency of insertion sort
decreases distance between comparisons
7. Example
Again, compare and swap the values, if required, in the original array.
After this step, the array should look like this −
Finally, the rest of the array sorted using interval
of value 1. Shell sort uses insertion sort to sort the
array.
8. Example
We see that it
required only four
swaps to sort the rest
of the array.
10. Empirical Analysis of Shell Sort
(Advantage)
Fastest of all O (N^2) sorting algorithms
it’s only efficient for medium size lists
Five (5) times faster than the bubble sort
a little over twice as fast as the insertion sort
11. Empirical Analysis of Shell Sort
(Dis-advantage)
it is a complex algorithm
it’s not nearly as efficient as the merge, heap, and quick sorts
still significantly slower than the merge, heap, and quick sorts
also an excellent choice for repetitive sorting of smaller lists.
12. Shell Sort Best Case
when the array is already sorted in the right order
the number of comparisons is less.
13. Shell Sort Worst Case
running time of Shell sort depends on the choice of increment
sequence.
pairs of increments are not necessarily relatively prime and smaller
increments can have little effect.
15. Radix Sort
Founded by Harold H. Seward in 1954.
Radix sort is a non-comparative integer sorting algorithm that sorts
data with integer keys by grouping keys by the individual digits which
share the same significant position and value.
Unlike other sorting methods, radix sort considers the structure of the
keys
Sorting is done by comparing bits in the same position
Extension to keys that are alphanumeric strings
16. How does Radix Sort Works?
sorts by grouping numbers by their individual digits (or by
their radix).
It uses each radix digit as a key, and implements counting sort or
bucket sort under the hood in order to do the work of sorting.
Take the least significant digit of each key.
Group the keys based on that digit, but otherwise keep the original
order of keys.
Repeat the grouping process with each more significant digit.
20. Complexity
The complexity of radix sort is linear, which in terms of omega means
O(n). That is a great benefit in performance compared to O(n.log(n))
or even worse with O(n2) as we can see on the following chart.
21. Why using radix sort?
1. It’s fast
Radix sort is very fast compared to other sorting algorithms as we saw on
the diagram above. This algorithm is very useful in practice because in
practice we often sort sets of integers.
2. It’s easy to understand and implement
Even a beginner can understand and implement radix sort, which is
great. You need no more than few loops to implement it.
22. Why NOT using radix sort?
1. Works only with integers
If you’re not sure about the input better do not use radix sort. We may
think that our input consists only of integers and we can go for radix
sort, but what if in the future someone passes floats or strings to our
routine.
2. Requires additional space
Radix sort needs additional space – at least as much as the input.
24. Final Words
Radix sort is restricted by the input’s domain, but I must say that in
practice there are tons of cases where only integers are sorted. This is
when we get some data from the based on primary keys – typically
primary in database tables are integers as well. So practically there
are lots of cases of sorting integers, so radix sort may be one very,
very useful algorithm and it is so cool that it is also easy to
implement.