Shell sort in java2 min read

In this post, we will learn how to implement Shell Sort in java.
Sorting Algorithm in java.

Shell Sort Algorithm

Shell sort is in-place comparison-based sorting algorithm and variation of Insertion sort.
it is a better version of Insertion sort in comparison based. It can compare the elements far apart whereas Insertion compares adjacent elements.
In shell sort, we make the array h-sorted for a large value of h. We keep reducing the value of h until it becomes 1. An array is said to be h-sorted if all sublists of every h’th element are sorted.

Shell sort

Time Complexity of Shell Sort:

Best case:  0(nlogn)
Average case:  0(n(logn)^2)
Worst case:  0(n(logn)^2)

Implementation of Shell sort in java

The output of shell Sort Algorithm in java:

Also, learn:
Bubble Sort
Heap Sort
Insertion Sort
Quick Sort
Merge Sort