I was asked by an interviewer, the question is simple, find the top 100 from 1 million integers (32-bits).
When I was solving the question, I thought if I put all the 1 million integers into the memory, that would take up 4 MB space.
My question probably has nothing to do with the interview question, but here it is:
if the 1 million integers are store in a file num.txt, and further more, I want to read the all out of file and put them in memory (store them in an array probably), then how many IO will it take?
What you wanna do in this question if a scan.
You wanna have an array, or perhaps a priority-queue, that holds 100 integers and just store the largest 100 you see.
You don’t wanna take the take in the file one page at the time, perhaps using something like
mmap.the number of IO’s will be the size of 1mio. integers divided by the pagesize.