Shell Sort

Shell sort is a sorting algorithm that is based on the insertion sort algorithm. If the smaller value is on the far right and must be relocated to the far left, this technique avoids huge shifts as in insertion sort.

This algorithm employs insertion sort on widely distributed elements, first sorting them and then sorting the less widely distributed elements. This space is known as an interval. Based on Knuth’s formula, this interval is calculated as :

Knuth’s Formula

h = h * 3 + 1
where −
   h is interval with initial value 1

This approach is quite efficient for medium-sized data sets because the average and worst-case complexity of this algorithm is O(n), where n is the number of elements. In addition, the worst-case space complexity is O. (n).

Algorithm

Following is the algorithm for shell sort.

Step 1 − Initialize the value of h
Step 2 − Divide the list into smaller sub-list of equal interval h
Step 3 − Sort these sub-lists using insertion sort
Step 3 − Repeat until complete list is sorted

Pseudocode

Following is the pseudocode for shell sort.

procedure shellSort()
   A : array of items 
	
   /* calculate interval*/
   while interval < A.length /3 do:
      interval = interval * 3 + 1	    
   end while
   
   while interval > 0 do:

      for outer = interval; outer < A.length; outer ++ do:

      /* select value to be inserted */
      valueToInsert = A[outer]
      inner = outer;

         /*shift element towards right*/
         while inner > interval -1 && A[inner - interval] >= valueToInsert do:
            A[inner] = A[inner - interval]
            inner = inner - interval
         end while

      /* insert the number at hole position */
      A[inner] = valueToInsert

      end for

   /* calculate interval*/
   interval = (interval -1) /3;	  

   end while
   
end procedure
0

5,623 thoughts on “Shell Sort”

  1. Very great post. I simply stumbled upon your weblog and wished to
    mention that I’ve really enjoyed browsing your blog posts.
    After all I will be subscribing for your rss feed and I hope you write once more very soon!

    0
  2. Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently fast.

    0
  3. Heya i am for the first time here. I came across this board and I find It really useful & it helped me out much. I hope to give something back and help others like you helped me.

    0
  4. Good site! I truly love how it is easy on my eyes and the data are well written. I am wondering how I could be notified when a new post has been made. I have subscribed to your feed which must do the trick! Have a nice day!

    0
  5. An attention-grabbing dialogue is worth comment. I feel that you should write more on this topic, it may not be a taboo topic but usually people are not enough to talk on such topics. To the next. Cheers

    0
  6. lisinopril 2 5 mg tablets [url=http://lisinoprilbestprice.store/#]lisinopril 2.5[/url] lisinopril 50 mg price

    0
  7. hello!,I like your writing very much! share we communicate more about your post on AOL? I need an expert on this area to solve my problem. May be that’s you! Looking forward to see you.

    0
  8. buying from online mexican pharmacy [url=http://mexicopharm.com/#]mexican pharmacy[/url] mexican drugstore online mexicopharm.com

    0
  9. online pharmacy canada [url=http://canadapharm.life/#]Pharmacies in Canada that ship to the US[/url] canadian drugs canadapharm.life

    0
  10. ed meds online without doctor prescription [url=http://edpillsdelivery.pro/#]over the counter erectile dysfunction pills[/url] generic ed drugs

    0
  11. tadalafil tablets 20 mg online [url=http://tadalafildelivery.pro/#]Tadalafil 20mg price in Canada[/url] buy tadalafil online canada

    0
  12. cheap erectile dysfunction pills online [url=http://edpillsdelivery.pro/#]best non prescription ed pills[/url] best drug for ed

    0
  13. zithromax order online uk [url=https://azithromycin.store/#]where can i buy zithromax capsules[/url] buy zithromax online fast shipping

    0
  14. I think this is one of the most vital information for me. And i am glad reading your article. But should remark on few general things, The web site style is perfect, the articles is really excellent : D. Good job, cheers

    0
  15. excellent publish, very informative. I ponder why the opposite experts of this sector don’t realize this. You must continue your writing. I am confident, you have a huge readers’ base already!

    0
  16. zithromax prescription [url=http://azithromycin.store/#]zithromax best price[/url] can you buy zithromax online

    0
  17. comprare farmaci online con ricetta [url=https://farmaciaitalia.store/#]farmacia online miglior prezzo[/url] farmacia online

    0
  18. farmacie online autorizzate elenco [url=https://kamagraitalia.shop/#]kamagra oral jelly[/url] acquistare farmaci senza ricetta

    0
  19. online pharmacy india [url=https://indiapharm.life/#]reputable indian online pharmacy[/url] pharmacy website india

    0
  20. Good ?V I should definitely pronounce, impressed with your website. I had no trouble navigating through all the tabs and related information ended up being truly simple to do to access. I recently found what I hoped for before you know it in the least. Reasonably unusual. Is likely to appreciate it for those who add forums or something, web site theme . a tones way for your client to communicate. Excellent task..

    0
  21. buy medicines online in india [url=https://indiapharm.life/#]mail order pharmacy india[/url] india pharmacy mail order

    0
  22. Hiya very cool site!! Guy .. Beautiful .. Superb .. I will bookmark your blog and take the feeds alsoKI’m satisfied to find so many helpful info right here within the put up, we’d like develop extra strategies in this regard, thanks for sharing. . . . . .

    0
  23. online prednisone 5mg [url=https://prednisonepharm.store/#]buy prednisone online without a script[/url] prednisone 20mg online without prescription

    0
  24. brand prednisone [url=https://prednisonepharm.store/#]prednisone cream brand name[/url] prednisone without prescription medication

    0
  25. buy prescription drugs without doctor [url=http://edwithoutdoctorprescription.store/#]buy prescription drugs without doctor[/url] viagra without doctor prescription amazon

    0
  26. viagra without doctor prescription [url=https://edwithoutdoctorprescription.store/#]buy prescription drugs without doctor[/url] prescription drugs online

    0
  27. ed meds online without doctor prescription [url=https://edwithoutdoctorprescription.store/#]tadalafil without a doctor’s prescription[/url] best ed pills non prescription

    0
  28. ed prescription drugs [url=http://edwithoutdoctorprescription.store/#]buy prescription drugs without doctor[/url] prescription drugs online

    0
  29. reputable mexican pharmacies online [url=https://mexicanpharmacy.win/#]Mexico pharmacy[/url] mexican pharmacy mexicanpharmacy.win

    0
  30. best online pharmacies in mexico [url=http://mexicanpharmacy.win/#]Medicines Mexico[/url] medicine in mexico pharmacies mexicanpharmacy.win

    0
  31. safe online pharmacies in canada [url=http://canadianpharmacy.pro/#]canada ed drugs[/url] canadian pharmacy 24 com canadianpharmacy.pro

    0
  32. my canadian pharmacy review [url=https://canadianpharmacy.pro/#]Pharmacies in Canada that ship to the US[/url] canadian drugs canadianpharmacy.pro

    0
  33. mexico pharmacy [url=http://mexicanpharmacy.win/#]online mexican pharmacy[/url] buying prescription drugs in mexico mexicanpharmacy.win

    0
  34. best canadian pharmacy online [url=https://canadianpharmacy.pro/#]Canada Pharmacy[/url] best rated canadian pharmacy canadianpharmacy.pro

    0
  35. Online medicine order [url=http://indianpharmacy.shop/#]indian pharmacy to usa[/url] top online pharmacy india indianpharmacy.shop

    0
  36. pharmacy canadian [url=http://canadianpharmacy.pro/#]canadian neighbor pharmacy[/url] canadian pharmacy meds canadianpharmacy.pro

    0
  37. mexico drug stores pharmacies [url=http://mexicanpharmacy.win/#]mexican pharmacy online[/url] mexican online pharmacies prescription drugs mexicanpharmacy.win

    0
  38. canada drugs online [url=https://canadianpharmacy.pro/#]Pharmacies in Canada that ship to the US[/url] canadian pharmacy oxycodone canadianpharmacy.pro

    0
  39. online shopping pharmacy india [url=https://indianpharmacy.shop/#]indian pharmacy to usa[/url] buy medicines online in india indianpharmacy.shop

    0
  40. Pharmacie en ligne fiable [url=https://cialissansordonnance.shop/#]cialissansordonnance.shop[/url] Pharmacie en ligne livraison 24h

    0
  41. Acheter mГ©dicaments sans ordonnance sur internet [url=http://acheterkamagra.pro/#]kamagra gel[/url] Pharmacie en ligne livraison 24h

    0
  42. Acheter mГ©dicaments sans ordonnance sur internet [url=https://acheterkamagra.pro/#]Pharmacie en ligne France[/url] Pharmacie en ligne livraison 24h

    0
  43. Pharmacies en ligne certifiГ©es [url=http://cialissansordonnance.shop/#]Pharmacie en ligne sans ordonnance[/url] Pharmacies en ligne certifiГ©es

    0
  44. Pharmacie en ligne fiable [url=http://levitrasansordonnance.pro/#]levitra generique prix en pharmacie[/url] pharmacie ouverte

    0
  45. Pharmacies en ligne certifiГ©es [url=https://pharmadoc.pro/#]pharmacie en ligne[/url] Pharmacie en ligne livraison gratuite

    0
  46. amoxicillin 500 mg without prescription [url=https://amoxicillin.bid/#]generic amoxicillin 500mg[/url] amoxicillin 500mg tablets price in india

    0
  47. zithromax 500 mg lowest price online [url=https://azithromycin.bid/#]generic zithromax 500mg india[/url] zithromax drug

    0
  48. 50 mg prednisone from canada [url=http://prednisonetablets.shop/#]can i buy prednisone online without prescription[/url] price of prednisone 5mg

    0
  49. generic zithromax azithromycin [url=http://azithromycin.bid/#]zithromax canadian pharmacy[/url] zithromax for sale us

    0
  50. Online medicine order [url=http://indianpharm.store/#]Indian pharmacy to USA[/url] top online pharmacy india indianpharm.store

    0
  51. reputable indian online pharmacy [url=https://indianpharm.store/#]order medicine from india to usa[/url] reputable indian online pharmacy indianpharm.store

    0
  52. the canadian pharmacy [url=https://canadianpharm.store/#]Best Canadian online pharmacy[/url] safe reliable canadian pharmacy canadianpharm.store

    0
  53. pharmacies in mexico that ship to usa [url=http://mexicanpharm.shop/#]buying prescription drugs in mexico online[/url] buying from online mexican pharmacy mexicanpharm.shop

    0
  54. mexico drug stores pharmacies [url=https://mexicanpharm.shop/#]Online Pharmacies in Mexico[/url] mexico drug stores pharmacies mexicanpharm.shop

    0
  55. canadian drugs [url=https://canadianpharm.store/#]Certified Online Pharmacy Canada[/url] canadian pharmacy sarasota canadianpharm.store

    0
  56. indianpharmacy com [url=https://indianpharm.store/#]Indian pharmacy to USA[/url] indian pharmacy indianpharm.store

    0
  57. top online pharmacy india [url=http://indianpharm.store/#]order medicine from india to usa[/url] india pharmacy mail order indianpharm.store

    0
  58. india pharmacy [url=https://indianpharm.store/#]order medicine from india to usa[/url] india pharmacy mail order indianpharm.store

    0
  59. canadapharmacyonline.com [url=http://canadadrugs.pro/#]canadian drug store viagra[/url] most reliable canadian pharmacies

    0
  60. canadian medication [url=https://canadadrugs.pro/#]canada pharmaceutical online ordering[/url] legitimate canadian online pharmacy

    0