Resource · Guide or article
Shellsort
Shellsort, a gap-based generalization of insertion sort, traced on a concrete eight-value array.
Reviewed
Open the original: Shellsort (opens the original site in a new tab)Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
Read this in other languages: Português. Shellsort, also known as Shell sort or Shell's method, is an in-place comparison sort. It can be seen as either a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort). The method starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared. Starting with far apart elements, it can move some out-of-place elements into position faster than a simple nearest neighbor exchange For our example and ease of understanding, we take the interval of 4. Make a virtual sub-list of all values located at the interval of 4 positions. Here these values are {35, 14}, {33, 19}, {42, 27} and {10, 44}
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Reference
What it covers
- How Shell Sort Works: sub-lists at gap 4, then gap 2, then a final insertion-sort pass at gap 1.
- A correction note for a typo in one of the step images.
- Complexity table: n log(n) best, worst n (log(n)) squared, average depends on gap sequence, memory 1, not stable.
How to use it
PrepKit study advice, not a claim made by the source.
Trace the example array through gaps 4, 2, and 1 by hand, then code it and compare with plain insertion sort.
Scope and limitations
Step images come from TutorialsPoint and one contains a typo the README corrects. Gap sequences are not compared. A Portuguese version is linked.
Access and format
English README on GitHub, free to read, in the MIT-licensed trekhleb/javascript-algorithms repository.
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88
Evidence behind this overview
- src/algorithms/sorting/shell-sort/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.