# 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

### 1,937 thoughts on “Shell Sort”

piece of writing, keep it up.

0
2. 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
3. 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
4. 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
5. 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
6. Helpful info. Fortunate me I found your web site by chance, and I am stunned why this accident didn’t took place in advance! I bookmarked it.

0
7. 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
8. lisinopril 2 5 mg tablets [url=http://lisinoprilbestprice.store/#]lisinopril 2.5[/url] lisinopril 50 mg price

0
9. purchase cytotec [url=https://cytotec.icu/#]Abortion pills online[/url] buy cytotec online

0
10. cheap zithromax pills [url=http://zithromaxbestprice.icu/#]zithromax 500 tablet[/url] zithromax z-pak

0
11. 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
12. buying from online mexican pharmacy [url=http://mexicopharm.com/#]mexican pharmacy[/url] mexican drugstore online mexicopharm.com

0

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

0

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

0
17. paxlovid generic [url=https://paxlovid.guru/#]paxlovid best price[/url] Paxlovid over the counter

0
18. Paxlovid over the counter [url=https://paxlovid.guru/#]Paxlovid buy online[/url] paxlovid generic

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

0
20. 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
21. 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
22. zithromax prescription [url=http://azithromycin.store/#]zithromax best price[/url] can you buy zithromax online

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

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

0

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

0
27. 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
28. buy medicines online in india [url=https://indiapharm.life/#]mail order pharmacy india[/url] india pharmacy mail order

0
29. 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
30. online prednisone 5mg [url=https://prednisonepharm.store/#]buy prednisone online without a script[/url] prednisone 20mg online without prescription

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

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

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

0
34. ed medications list [url=https://edpills.bid/#]non prescription erection pills[/url] new treatments for ed

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

0
36. erection pills that work [url=https://edpills.bid/#]best otc ed pills[/url] mens erection pills

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

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

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

0

0

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

0

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

0

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

0

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

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

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

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

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

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

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

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

0
56. amoxicillin 500 mg brand name [url=https://amoxicillin.bid/#]amoxicillin 250 mg capsule[/url] amoxicillin discount

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

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

0
59. prednisone nz [url=http://prednisonetablets.shop/#]cheapest prednisone no prescription[/url] prednisone 475

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

0
61. 20 mg prednisone [url=https://prednisonetablets.shop/#]25 mg prednisone[/url] prednisone 1 mg for sale

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

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

0

0
65. 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
66. mexico drug stores pharmacies [url=https://mexicanpharm.shop/#]Online Pharmacies in Mexico[/url] mexico drug stores pharmacies mexicanpharm.shop

0

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

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

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

0