{"id":50408,"date":"2025-05-28T17:33:54","date_gmt":"2025-05-28T12:03:54","guid":{"rendered":"https:\/\/www.iquanta.in\/blog\/?p=50408"},"modified":"2025-05-28T17:33:56","modified_gmt":"2025-05-28T12:03:56","slug":"shell-sort-algorithm-in-data-structures-with-code-examples","status":"publish","type":"post","link":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/","title":{"rendered":"Shell Sort Algorithm in Data Structures with Code Examples"},"content":{"rendered":"\n<p>Sorting means putting things in order like smallest to biggest or A to Z. Computers also need to sort stuff like numbers names or files. One way to do this is Shell Sort. It is like a better version of Insertion Sort that works faster on big lists.<\/p>\n\n\n\n<p>Shell Sort was made by a smart guy named Donald Shell in 1959. It works by comparing items that are far apart first and then slowly making the gap smaller. This helps move big numbers quickly to the right place.<\/p>\n\n\n\n<p>Think of it like sorting books on a shelf. Instead of moving one book at a time Shell Sort checks and moves books that are far away and then keeps checking closer and closer books until all are in order. It&#8217;s smart and fast when used right. In this blog we will learn how Shell Sort works with easy examples code and where it is used in real life.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/chat.whatsapp.com\/B6weknl7133BQXjPva0pgB\"><img fetchpriority=\"high\" decoding=\"async\" width=\"875\" height=\"142\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-187.png\" alt=\"Shell Sort Algorithm\" class=\"wp-image-50403\" srcset=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-187.png 875w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-187-300x49.png 300w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-187-768x125.png 768w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-187-150x24.png 150w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-187-696x113.png 696w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure><\/div>\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_77 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#What_is_Shell_Sort_Algorithm\" >What is Shell Sort Algorithm?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Why_Use_Shell_Sort_Algorithm\" >Why Use Shell Sort Algorithm?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#How_Shell_Sort_Algorithm_Works\" >How Shell Sort Algorithm Works?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Example_of_Shell_Sort\" >Example of Shell Sort<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Shell_Sort_Algorithm_Code_in_Python\" >Shell Sort Algorithm Code in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Time_and_Space_Complexity_of_Shell_Sort\" >Time and Space Complexity of Shell Sort<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Applications_of_Shell_Sort_Algorithm\" >Applications of Shell Sort Algorithm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Advantages_of_Shell_Sort_Algorithm\" >Advantages of Shell Sort Algorithm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Disadvantages_of_Shell_Sort_Algorithm\" >Disadvantages of Shell Sort Algorithm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#FAQs_Shell_Sort_Algorithm\" >FAQs (Shell Sort Algorithm)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#What_is_Shell_Sort\" >What is Shell Sort?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Is_Shell_Sort_a_stable_sorting_algorithm\" >Is Shell Sort a stable sorting algorithm?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#What_is_the_time_complexity_of_Shell_Sort\" >What is the time complexity of Shell Sort?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#Does_Shell_Sort_use_extra_memory\" >Does Shell Sort use extra memory?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#When_is_Shell_Sort_a_good_choice\" >When is Shell Sort a good choice?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-is-shell-sort-algorithm\"><span class=\"ez-toc-section\" id=\"What_is_Shell_Sort_Algorithm\"><\/span><strong>What is Shell Sort Algorithm?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Shell Sort is just a smart way to sort a list. It is kind of like Insertion Sort but faster and better. Instead of checking one number at a time Shell Sort checks numbers that are far apart and slowly brings them closer.<\/p>\n\n\n\n<p>Imagine you have a messy row of shoes. Instead of fixing one shoe at a time you first fix the ones that are far from each other. Then you fix closer ones and so on until all the shoes are in order. That is how Shell Sort works.<\/p>\n\n\n\n<p>It uses something called a gap to decide how far apart the numbers should be. In the beginning the gap is big then it keeps getting smaller. In the end when the gap becomes one it finishes the sorting just like Insertion Sort. So Shell Sort is just a sorting method that works step-by-step by shrinking the gap and putting things in the right order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-use-shell-sort-algorithm\"><span class=\"ez-toc-section\" id=\"Why_Use_Shell_Sort_Algorithm\"><\/span><strong>Why Use Shell Sort Algorithm?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes normal sorting like Bubble Sort or Insertion Sort is too slow when there are many things to sort. Shell Sort is faster because it doesn\u2019t just move things one by one. It moves them in big jumps first then smaller jumps.<\/p>\n\n\n\n<p>Let\u2019s say your toys are all messed up in a long line. Instead of fixing one toy at a time from start to end you fix toys that are far apart first. That saves a lot of time. That\u2019s what Shell Sort does.<\/p>\n\n\n\n<p>It is also easy to understand and doesn\u2019t need much extra space like some other sorting methods. So it\u2019s a good mix of simple and fast. Shell Sort is helpful when your data is already kind of sorted but not fully. It makes it neat quickly without too much work. So we use Shell Sort when we want faster sorting without making things too complex.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/chat.whatsapp.com\/B6weknl7133BQXjPva0pgB\"><img decoding=\"async\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-187.png\" alt=\"Shell Sort Algorithm\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-shell-sort-algorithm-works\"><span class=\"ez-toc-section\" id=\"How_Shell_Sort_Algorithm_Works\"><\/span><strong>How Shell Sort Algorithm Works?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Shell Sort works by sorting items that are far apart first. It uses a number called a &#8220;gap&#8221; to decide how far apart the comparisons should be. In the beginning, it picks a big gap and sorts elements that are that far apart. Then it keeps making the gap smaller and smaller, fixing the order each time. In the end, when the gap becomes 1, it just does a normal sort like Insertion Sort. This method helps big numbers move to their correct place faster so we don\u2019t have to shift them step by step.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_of_Shell_Sort\"><\/span><strong>Example of Shell Sort<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Let\u2019s say you have a list:<br>[23, 12, 1, 8, 34, 54, 2, 3]<\/p>\n\n\n\n<ol>\n<li>Start with gap = 4. Compare numbers that are 4 apart.<\/li>\n\n\n\n<li>Reduce gap to 2 and sort again using that gap.<\/li>\n\n\n\n<li>Reduce gap to 1. Now sort everything like Insertion Sort.<\/li>\n\n\n\n<li>Final sorted list: [1, 2, 3, 8, 12, 23, 34, 54]<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-shell-sort-algorithm-code-in-python\"><span class=\"ez-toc-section\" id=\"Shell_Sort_Algorithm_Code_in_Python\"><\/span><strong>Shell Sort Algorithm Code in Python<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def shell_sort(arr):\n    n = len(arr)\n    gap = n \/\/ 2\n\n    while gap &gt; 0:\n        for i in range(gap, n):\n            temp = arr&#091;i]\n            j = i\n\n            while j &gt;= gap and arr&#091;j - gap] &gt; temp:\n                arr&#091;j] = arr&#091;j - gap]\n                j -= gap\n\n            arr&#091;j] = temp\n        gap \/\/= 2\n\n    return arr\n\n# Example usage\nmy_list = &#091;23, 12, 1, 8, 34, 54, 2, 3]\nsorted_list = shell_sort(my_list)\nprint(\"Sorted list:\", sorted_list)\n\n<\/code><\/pre>\n\n\n\n<p>This code is just trying to sort a list of numbers using the Shell Sort method. First, it looks at how long the list is and picks a starting gap by dividing the length by 2. <\/p>\n\n\n\n<p>The gap tells how far apart we will compare numbers. While the gap is more than 0, we keep comparing numbers that are that far apart. If the number in front is bigger than the one behind, we move it back until it&#8217;s in the right place. We keep doing this for all numbers in the list. Then we make the gap smaller and do it again. <\/p>\n\n\n\n<p>In the end, the gap becomes 1, and we do normal sorting like Insertion Sort. After all this, the list is fully sorted. The code then prints the sorted list at the end.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-time-and-space-complexity-of-shell-sort\"><span class=\"ez-toc-section\" id=\"Time_and_Space_Complexity_of_Shell_Sort\"><\/span><strong>Time and Space Complexity of Shell Sort<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Case<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Time Complexity<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Best Case<\/td><td class=\"has-text-align-center\" data-align=\"center\">O(n log n)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Average Case<\/td><td class=\"has-text-align-center\" data-align=\"center\">O(n log\u00b2 n)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Worst Case<\/td><td class=\"has-text-align-center\" data-align=\"center\">O(n\u00b2)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Space Complexity<\/td><td class=\"has-text-align-center\" data-align=\"center\">O(1)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-applications-of-shell-sort-algorithm\"><span class=\"ez-toc-section\" id=\"Applications_of_Shell_Sort_Algorithm\"><\/span><strong>Applications of Shell Sort Algorithm<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol>\n<li>Shell Sort works well for small to medium-sized lists that are partially sorted already. It can quickly finish sorting without much hassle.<\/li>\n\n\n\n<li>It is useful when you want a simple algorithm that is faster than Insertion or Bubble sort. Good for basic sorting tasks without needing extra memory.<\/li>\n\n\n\n<li>Shell Sort can be used in embedded systems or places with low memory. Because it does not need much extra space to work.<\/li>\n\n\n\n<li>It is helpful in sorting data where elements are spread out evenly. This helps Shell Sort jump around and fix things fast.<\/li>\n\n\n\n<li>Shell Sort is good for educational purposes to teach gap-based sorting. It helps learners understand how sorting can be improved step-by-step.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-advantages-of-shell-sort-algorithm\"><span class=\"ez-toc-section\" id=\"Advantages_of_Shell_Sort_Algorithm\"><\/span><strong>Advantages of Shell Sort Algorithm<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol>\n<li>It fixes big mistakes early by moving far apart elements.<\/li>\n\n\n\n<li>Uses very little extra memory.<\/li>\n\n\n\n<li>Easy to understand and write in code.<\/li>\n\n\n\n<li>Faster than simple sorts like bubble or insertion sort.<\/li>\n\n\n\n<li>Works especially well if the list is already somewhat sorted.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-disadvantages-of-shell-sort-algorithm\"><span class=\"ez-toc-section\" id=\"Disadvantages_of_Shell_Sort_Algorithm\"><\/span><strong>Disadvantages of Shell Sort Algorithm<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol>\n<li>It can change the order of equal items (not stable).<\/li>\n\n\n\n<li>Speed depends a lot on the choice of gap sizes.<\/li>\n\n\n\n<li>No fixed best method to choose the gaps.<\/li>\n\n\n\n<li>Can still be slow (worst case is like simple sorts).<\/li>\n\n\n\n<li>Not the best choice for very large lists compared to advanced sorts.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/chat.whatsapp.com\/B6weknl7133BQXjPva0pgB\"><img decoding=\"async\" width=\"875\" height=\"142\" src=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-188.png\" alt=\"\" class=\"wp-image-50436\" srcset=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-188.png 875w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-188-300x49.png 300w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-188-768x125.png 768w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-188-150x24.png 150w, https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/image-188-696x113.png 696w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faqs-shell-sort-algorithm\"><span class=\"ez-toc-section\" id=\"FAQs_Shell_Sort_Algorithm\"><\/span><strong>FAQs (Shell Sort Algorithm)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-is-shell-sort\"><span class=\"ez-toc-section\" id=\"What_is_Shell_Sort\"><\/span><strong>What is Shell Sort?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Shell Sort is a sorting algorithm that improves insertion sort by comparing and swapping elements far apart, gradually reducing the gap until the list is sorted.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-is-shell-sort-a-stable-sorting-algorithm\"><span class=\"ez-toc-section\" id=\"Is_Shell_Sort_a_stable_sorting_algorithm\"><\/span><strong>Is Shell Sort a stable sorting algorithm?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>No, Shell Sort is not stable because it can change the order of equal elements<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-is-the-time-complexity-of-shell-sort\"><span class=\"ez-toc-section\" id=\"What_is_the_time_complexity_of_Shell_Sort\"><\/span><strong>What is the time complexity of Shell Sort?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The time complexity varies with the gap sequence, but generally, the worst case can be as bad as O(n\u00b2), and the average case is better than simple sorts like bubble sort.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-does-shell-sort-use-extra-memory\"><span class=\"ez-toc-section\" id=\"Does_Shell_Sort_use_extra_memory\"><\/span><strong>Does Shell Sort use extra memory?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>No, it is an in-place sorting algorithm and uses very little extra memory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-when-is-shell-sort-a-good-choice\"><span class=\"ez-toc-section\" id=\"When_is_Shell_Sort_a_good_choice\"><\/span><strong>When is Shell Sort a good choice?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Shell Sort works well for medium-sized arrays and partially sorted data, but for very large datasets, faster algorithms like quicksort or merge sort are preferred.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorting means putting things in order like smallest to biggest or A to Z. Computers also need to sort stuff like numbers names or files. One way to do this is Shell Sort. It is like a better version of Insertion Sort that works faster on big lists. Shell Sort was made by a smart [&hellip;]<\/p>\n","protected":false},"author":560,"featured_media":50439,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1075,1073],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.4 (Yoast SEO v21.9.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Shell Sort Algorithm in Data Structures with Code Examples - iQuanta<\/title>\n<meta name=\"description\" content=\"In this blog we will learn how Shell Sort works with easy examples code and where it is used in real life.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Shell Sort Algorithm in Data Structures with Code Examples\" \/>\n<meta property=\"og:description\" content=\"In this blog we will learn how Shell Sort works with easy examples code and where it is used in real life.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"iQuanta\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/iquanta.in\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-28T12:03:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-28T12:03:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/Your-paragraph-text-23.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nidhi Goswami\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nidhi Goswami\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/\"},\"author\":{\"name\":\"Nidhi Goswami\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/ec8c8c25d0526dd86557b6fed064f7f3\"},\"headline\":\"Shell Sort Algorithm in Data Structures with Code Examples\",\"datePublished\":\"2025-05-28T12:03:54+00:00\",\"dateModified\":\"2025-05-28T12:03:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/\"},\"wordCount\":1161,\"publisher\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/#organization\"},\"articleSection\":[\"DSA and Competitive Programming\",\"iSkills\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/\",\"url\":\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/\",\"name\":\"Shell Sort Algorithm in Data Structures with Code Examples - iQuanta\",\"isPartOf\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/#website\"},\"datePublished\":\"2025-05-28T12:03:54+00:00\",\"dateModified\":\"2025-05-28T12:03:56+00:00\",\"description\":\"In this blog we will learn how Shell Sort works with easy examples code and where it is used in real life.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.iquanta.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Shell Sort Algorithm in Data Structures with Code Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#website\",\"url\":\"https:\/\/www.iquanta.in\/blog\/\",\"name\":\"iQuanta | Cat Preparation Online\",\"description\":\"Building Learning Networks\",\"publisher\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.iquanta.in\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#organization\",\"name\":\"IQuanta\",\"url\":\"https:\/\/www.iquanta.in\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2018\/08\/IQuanta-1.png\",\"contentUrl\":\"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2018\/08\/IQuanta-1.png\",\"width\":525,\"height\":200,\"caption\":\"IQuanta\"},\"image\":{\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/facebook.com\/iquanta.in\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/ec8c8c25d0526dd86557b6fed064f7f3\",\"name\":\"Nidhi Goswami\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21d234d87afd924b217d26b25a3cf1ee?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21d234d87afd924b217d26b25a3cf1ee?s=96&d=mm&r=g\",\"caption\":\"Nidhi Goswami\"},\"url\":\"https:\/\/www.iquanta.in\/blog\/author\/nidhigoswami\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Shell Sort Algorithm in Data Structures with Code Examples - iQuanta","description":"In this blog we will learn how Shell Sort works with easy examples code and where it is used in real life.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/","og_locale":"en_US","og_type":"article","og_title":"Shell Sort Algorithm in Data Structures with Code Examples","og_description":"In this blog we will learn how Shell Sort works with easy examples code and where it is used in real life.","og_url":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/","og_site_name":"iQuanta","article_publisher":"https:\/\/facebook.com\/iquanta.in","article_published_time":"2025-05-28T12:03:54+00:00","article_modified_time":"2025-05-28T12:03:56+00:00","og_image":[{"width":1600,"height":900,"url":"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2025\/05\/Your-paragraph-text-23.jpg","type":"image\/jpeg"}],"author":"Nidhi Goswami","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nidhi Goswami","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#article","isPartOf":{"@id":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/"},"author":{"name":"Nidhi Goswami","@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/ec8c8c25d0526dd86557b6fed064f7f3"},"headline":"Shell Sort Algorithm in Data Structures with Code Examples","datePublished":"2025-05-28T12:03:54+00:00","dateModified":"2025-05-28T12:03:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/"},"wordCount":1161,"publisher":{"@id":"https:\/\/www.iquanta.in\/blog\/#organization"},"articleSection":["DSA and Competitive Programming","iSkills"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/","url":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/","name":"Shell Sort Algorithm in Data Structures with Code Examples - iQuanta","isPartOf":{"@id":"https:\/\/www.iquanta.in\/blog\/#website"},"datePublished":"2025-05-28T12:03:54+00:00","dateModified":"2025-05-28T12:03:56+00:00","description":"In this blog we will learn how Shell Sort works with easy examples code and where it is used in real life.","breadcrumb":{"@id":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.iquanta.in\/blog\/shell-sort-algorithm-in-data-structures-with-code-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.iquanta.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Shell Sort Algorithm in Data Structures with Code Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.iquanta.in\/blog\/#website","url":"https:\/\/www.iquanta.in\/blog\/","name":"iQuanta | Cat Preparation Online","description":"Building Learning Networks","publisher":{"@id":"https:\/\/www.iquanta.in\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.iquanta.in\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.iquanta.in\/blog\/#organization","name":"IQuanta","url":"https:\/\/www.iquanta.in\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2018\/08\/IQuanta-1.png","contentUrl":"https:\/\/www.iquanta.in\/blog\/wp-content\/uploads\/2018\/08\/IQuanta-1.png","width":525,"height":200,"caption":"IQuanta"},"image":{"@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/iquanta.in"]},{"@type":"Person","@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/ec8c8c25d0526dd86557b6fed064f7f3","name":"Nidhi Goswami","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.iquanta.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21d234d87afd924b217d26b25a3cf1ee?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21d234d87afd924b217d26b25a3cf1ee?s=96&d=mm&r=g","caption":"Nidhi Goswami"},"url":"https:\/\/www.iquanta.in\/blog\/author\/nidhigoswami\/"}]}},"_links":{"self":[{"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/posts\/50408"}],"collection":[{"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/users\/560"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/comments?post=50408"}],"version-history":[{"count":5,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/posts\/50408\/revisions"}],"predecessor-version":[{"id":50440,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/posts\/50408\/revisions\/50440"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/media\/50439"}],"wp:attachment":[{"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/media?parent=50408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/categories?post=50408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iquanta.in\/blog\/wp-json\/wp\/v2\/tags?post=50408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}