Shellsort, 2.48k-1 vs Tokuda's sequence
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Shellsort’s performance depends heavily on the gap sequence you choose. There is no single universally optimal sequence for every machine and input distribution, so comparisons such as geometric gaps around 2.2 to 2.5 versus Tokuda’s sequence are mostly about empirical tradeoffs rather than one simple theorem. The practical question is which sequence gives fewer comparisons and moves on realistic arrays.
Why Gap Sequences Matter
Shellsort works by running insertion-sort-like passes over elements separated by a gap, then shrinking the gap until it reaches 1.
A simplified implementation:
The gap sequence controls how much disorder is removed early and how much work remains for the final gap-1 pass.
The Geometric 2.48-Style Idea
A geometric sequence near 2.48 means successive gaps shrink by dividing by about 2.48. In practice, this produces a steadily decreasing progression with relatively simple generation.
A toy generator:
The details vary depending on how you round and where you start. The point is that the gaps come from a near-geometric progression.
These sequences are popular because they are easy to describe and often perform well empirically.
Tokuda’s Sequence
Tokuda proposed a specific empirically strong sequence that is often written in generated form and then truncated to the array size.
A common generator is:
Tokuda’s sequence is one of the classic Shellsort choices because it repeatedly shows strong practical performance in experiments.
Which One Is Better
The honest answer is: usually Tokuda is a strong default, but the exact winner depends on implementation details, array sizes, and hardware effects.
In broad terms:
- Tokuda is widely regarded as a strong empirical sequence
- geometric sequences near
2.2to2.5can also perform very well - the differences are often in constant factors, not in changing Shellsort into a fundamentally different asymptotic algorithm
If you are choosing a general-purpose Shellsort variant without deep tuning, Tokuda is often the safer off-the-shelf answer because it has a strong practical reputation.
If you are benchmarking a particular workload, measure both on your input distribution rather than assuming one mathematical-looking formula must always win.
Benchmarking the Sequences
A simple timing harness helps compare them directly.
This kind of experiment is more useful than arguing from formulas alone because Shellsort performance is famously sensitive to gap design and constant factors.
What Theory Does and Does Not Tell You
Shellsort is a good example of an algorithm where theory and practice are both interesting but not perfectly aligned. Many gap sequences are motivated by empirical results, and exact worst-case bounds do not always predict which sequence is best on ordinary random or partially ordered arrays.
So if the question is “which should I use in code,” the answer is often empirical. If the question is “which has a prettier closed form,” that is a different discussion.
Common Pitfalls
The most common mistake is assuming a gap sequence with a nice mathematical formula must automatically outperform others on real hardware. Another is comparing sequences without fixing the rest of the implementation, because insertion-pass details and language overhead also matter. Developers also often benchmark on one tiny array size and overgeneralize the result. A final issue is forgetting that Shellsort itself is already a niche choice in many contexts where simpler library sorts or faster asymptotic algorithms are available.
Summary
- Shellsort performance depends strongly on the gap sequence.
- Geometric sequences near
2.48can work well, but Tokuda is a strong practical default. - The “best” sequence is usually an empirical question, not a universally settled theorem.
- Benchmark the sequences on the input sizes and distributions you actually care about.
- Tokuda’s sequence is widely respected because it consistently performs well in practice.
Related reading
- Shortest distance between points algorithm
- Shortest path and sorting points in a 2-dimensional space
- Shortest path DFS, BFS or both?
- Shortest path fewest nodes for unweighted graph
- Shortest path in absence of the given edge
- Shortest path in graph where cost depends on the history of traversing
- Shortest path on a graph where distances change dynamically? maximum energy path
- Shortest Path to accomplish given scenario

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.