Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
stackoverflow.com
Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
1–10 of 63 posts
Re: Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
#2The thing is, you could just not worry about the stream, as it is TCP/IP based. The core idea is to read a number from the stream, append to the array that makes up the heap, and run heap sort.
The only important thing is to keep the tcp/ip connection alive. If sorting takes too much, tcp will take care of sending the last sent number again.
This might not be super efficient though.
This could also be done in batches (4kb? 8kb?) -- we don't know about network speed or latencies, so we might work on that.
Re: Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
#3Re: Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
#4Re: Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
#5Even if you don't read the book, that first chapter, "Cracking the Oyster", is worth a read. It's a fun problem.
[2]: https://learning.oreilly.com/library/view/programming-pearls...
Re: Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
#6I'd sort the input as it arrives, using heap sort. The thing is, you could just not worry about the stream, as it is TCP/IP based. The core idea is to read a number from the stream, append to the array that makes up the heap, and run heap sort. The only important thing is to keep the tcp/ip connection alive. If sorting takes too much, tcp will take care of sending the last sent number again. This might not be super e…
Re: Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
#7I'm not really smart enough to come up with such a solution, I'd probably just try and find a way to plug something in between the input or output Ethernet port that has a bit more memory.
Re: Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
#8https://en.wikipedia.org/wiki/External_sorting#External_merg...
Re: Sorting 1M 8-digit numbers in 1 MB of RAM (2012)
#9The relationship between cardinality of the codomain and image of the numbers is approximately 100
I would try to convert incoming numbers into pairs/tuples of N + differences (which can be done using less bits)