 Explore
Placement Prep Edit Edit

# Shell Sort Algorithm in C, C++, Java with Examples | FACE Prep

Published on 12 Mar 2020

In this article, we will be discussing about Shell Sort algorithm in C, C++, Java etc. Shell sort algorithm working, implementation, pseudo-code, time complexity, etc are also discussed here.

## What is Shell Sort Algorithm?

Shell sort algorithm is very similar to that of the Insertion sort algorithm. In case of Insertion sort, we move elements one position ahead to insert an element at its correct position. Whereas here, Shell sort starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared. Starting with far apart elements, it can move some out-of-place elements into the position faster than a simple nearest-neighbor exchange.

## A simple look at Shell Sort Vs Insertion Sort ## Shelling out the Shell Sort Algorithm with Examples

Here is an example to help you understand the working of Shell sort on array of elements name A = {17, 3, 9, 1, 8} ## Shell Sort in C, C++, Java

Here is the implementation of Shell sort in C, C++ and Java.

C
C++
Java

Output
Input- 4 3 7 1 8 5 Output- 1 3 4 7 8 5

## Shell Sort Time Complexity

Time complexity of above implementation of shellsort is O(n2). In the above implementation, gap is reduced by half in every iteration.

Check out more Data Structure Questions

## Also See Similar DS Sorting Techniques  