Enter an array separated by commas as : 16,15,15,10,1 or just press the hand icon to generate a random array then press enter or Sort button. Sorting will start and you can watch each pass as it gets sorted. When it shows green it means the two of them are being compared when red shows, it means the left number is greater than right number so it needs swapping The blue color means the number is at its correct position and thus sorted it will continue to check other numbers until it reaches end.
Shell sort was proposed by Donald Shell in 1959 as a generalization of insertion sort. It improves upon the insertion sort algorithm by allowing the exchange of items that are far apart, making it more efficient for larger datasets.
O(n log n)
– Efficient for certain sequences.O(n3/2)
– Dependent on the gap sequence
used.
O(n2)
– Similar to insertion sort for
certain gap
sequences.Space Complexity: O(1)
– It is an in-place sorting algorithm requiring
minimal additional space.
function shellSort(arr):
n = length(arr)
gap = n / 2
while gap > 0:
for i from gap to n:
temp = arr[i]
j = i
while j >= gap and arr[j - gap] > temp:
arr[j] = arr[j - gap]
j = j - gap
arr[j] = temp
gap = gap / 2
Shell sort is an efficient generalization of insertion sort that enhances performance through the use of gaps. With a time complexity that varies based on the gap sequence, it is particularly effective for small to medium datasets.