I have 2 database files and among those one I had to search for which I used 4 methods namely: in-memory sequential, in-memory binary, disk sequential and disk binary. The file which needed to be searched was 20Kb in size. The expected running time for these 4 programs should have been
disk sequential > disk binary > in-memory sequential > in-memory binary but its coming out to be
disk binary > disk sequential > in-memory sequential > in-memory binary.
Disk binary is taking around 1.5 sec more than the disk sequential. Why so?
I have calculated the time as printing the time before opening the file and then after opening the file and doing the search.
Thanks!
It can depends on the small size of your file; disk is not like main memory, it’s divided in blocks and your file won’t be probably bigger than 20 blocks.
So log_2(20) is about 5 and then binary search won’t be better unless what you’re searching for is after the fifth block.