我被一位面试官问到,问题很简单,find the top 100 from 1 million integers (32-bits)
。关于文件I/O的困惑
当我解决问题时,我想如果我put all the 1 million integers into the memory
,这将占用4 MB space
。
我的问题可能有无关的面试问题,但在这里它是:
如果100万个整数是在一个文件num.txt
店,并进一步,我想文件和put them in memory
的read the all out
(将它们存储在数组中),然后how many IO will it take
?
其实,先生,最大的最大3.8兆字节。除非每个整数都使用全部32位小数,否则可能会得到小得多的结果。对?假设百万位数的一半只有16位,只得到2.86102295兆字节。 – FreeSnow
@DadeLamkins,是的,你说得对,但是我想知道的是,如果我想从文件中读取所有32位整数,它应该采用多少IO。 – Alcott