0.0 General‎ > ‎General Notes‎ > ‎

Notes- Shell Sort

  • The Shell Sort is similar to the Bubble sort by the comparisonsand exchanges are made over greater distances.
    • in the Bubble Sort adjacent elements are compared and exchanged.
    • in the Shell Sort the distance is initialzed to the number of elements DIV 2
  • Each time the pass is complete with out a swap theGAP is divided by 2
  • on the last PASS, the shell sort acts just like the bubble sort.

Algorithm

Initialize the GAP to COUNT DIV 2 
loop while the GAP is greater than zero

set SWAPMADE to True
loop while SWAPMADE is True
set SWAPMADE to Falce
for CURRENT from 1 to COUNT less GAP 
if the CURRENT element is greater than the CURRENT + GAP element then 
Swap the two elements
Set SWAPMADE to True
endif
end for
end loop Determine the new GAP by dividing GAP by 2
Comments