#me looking at sorting algorithms: i just think they're neat!
Explore tagged Tumblr posts
Text
for an explanation of odd-even and shellsort, by the way:
Odd-Even looks at pairs of numbers in an line (1-2, 3-4, 5-6, 7-8), sees if they're in order, and flips them if they're not.
Then it alternates (1, 2-3, 4-5, 6-7, 8), checks if those are in order, and flips those if not.
It then goes back and forth until all the numbers are in sequential order.
Shellsort is more complicated but fun to watch a computer do.
This one compares numbers that are x distance apart and swaps those if they're not in sequential order.
X is usually however many numbers you're organizing, divided by two. Ignore the decimal (round down) if you get one.
When you get to the end of the line, divide X by two again (round down if needed) and do another pass. Keep going until you get to an X of one, then just keep passing through until it's sorted.
If you wanna be real fancy, when you do a successful swap and can go x backwards, you can check those numbers to see if they need to be swapped.
(actually you usually do backtrack while doing Shellsort, though this seems to be debatable.)
Honorary Mention: Comb Sort, which is like Shellsort but less cool in my opinion, and also I don't know how it works well enough to explain it.
Genuinely in love with it systems that incorporate structured randomness. Just a system that doesn't involve math or division, just wild and off-the wall guessing that's given a few rules for direction. No gods, no kings, just a computer playing with the logical equivalent of silly string.
3 notes
·
View notes