2025-12-31

The following incredibly small sorting algorithm has an $O(n^{4/3})$ worst-case runtime:

def fibonacci_sort(v):
a, b = 1, 1
while a * b < len(v):
a, b = b, a + b

while a > 0:
a, b = b - a, a
g = a * b
for i in range(g, len(v)):
while i >= g and v[i - g] > v[i]:
v[i], v[i - g] = v[i - g], v[i]
i -= g

As the name implies, it uses the Fibonacci sequence ($1, 1, 2, 3, 5, \dots$) to sort the elements. In this article I will explain how it works, show an interesting divisibility property of the Fibonacci numbers and use that to prove its complexity. I will also explain how I ended up with one of Donald Knuth’s coveted [reward checks](https://en.wikipedia.org/wi…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help