Live data from Hacker News

Spaghetti Sort (2018)

advent.morr.cc

1–10 of 55 posts

Re: Spaghetti Sort (2018)

#5
post #2

This is silly. The linear parts are just I/O, and the actual sorting happens in constant time by magic.

The sorting doesn’t happen in constant time. The actual sort happens by hand as you take out the largest pieces first. Until you do that, they aren’t in linear order.

Re: Spaghetti Sort (2018)

#6
Linear time O(n) means that as you keep adding numbers to sort, the time taken is bounded by a linear function of how many numbers you have. Since there is an upper bound on the number of spaghetti strands you can hold in your hand, eventually you need to "Slam their lower sides on the table" in batches, and then merge sort the results. However because unlike in merge sort there is an upper bound on the size of the sub lists you use spaghetti sort will actually be O(n^2) instead of O(n log(n)).

If you ignore the usual meaning of linear time and restrict yourself to sorting lists of numbers that will fit in your hand, then spaghetti sort always runs in less time that however long it takes to sort the maximum amount of spaghetti you can hold in your hand. i.e. constant time.

Post reply on HN