I'm attempting to figure out how the external merge sort algorithm works (I noticed other solutions to the same issue, but didn't find what I was looking for). I'm reading Jeffrey McConnell's book "Analysis Of Algorithms" and attempting to build the method mentioned in it.
For example, I have the following input data: 3,5,1,2,4,6,9,8,7, and I can only load four digits into memory.
My initial step is to read the input file in four-digit chunks, sort them in memory, and then write one to file A and the next to file B.
I got:
Now my issue is, how can I merge chunks from these files into larger ones if they won't fit in memory? According to Jeffrey McConnell, I need to read half portions and merge them into files C and D.Code:[COLOR=var(--black-800)]A:[1,2,3,5][7] [/COLOR][COLOR=var(--black-800)]B:[4,6,8,9][/COLOR]
But I got the sequencing wrong:
PS: I understand how to merge numbers by reading from a file, so I watched this video, which was really informative, but I'm not sure how to accomplish it with in-memory buffers to decrease I/O operations.Code:[COLOR=var(--black-800)]C:[1,2,4,6,3,8,5,9] [/COLOR][COLOR=var(--black-800)]D:[7][/COLOR]
Could someone kindly offer an example with step-by-step instructions?


Reply With Quote

