Google Interview Question
InternsCountry: United States
Interview Type: Written Test
What's a query?
Generally, divide input into 1000 batches, sort and output to different files. Then merge consecutively.
hello friends for this we don't need external sorting
10,00,000 instructions
1,000 at a time can sort
if we divide 10,00,000 instructions into 500 blocks
first sort first 2 block
then take last 500 sorted instruction and next 500 unsorted instructions ...sort them
now take first 500 sorted instruction of last sorted instruction and and above 500 instruction and sort them now we have 1500 sorted instruction similarly take next 500 instruction and make 2,000 sorted instruction and so on
for example
we have 16 integer and at a time i can take only 4 integer in memory and can perform sorting over then
5,6,1,3,2,3,1,1,7,6,3,8,8,7,6,5
divide them in block of 2 so it become
[5,6],[1,3],[2,3],[1,1],[7,6],[3,8],[8,7],[6,5]
now take first 2 block and sort them
[1,3],[5,6].......rest are unsorted
now take last sorted block and next unsorted block
and sort them
[1,3][2,3][5,6].....
then recursively sort the previous 2 blocks ([1,3]&[2,3]) until no block to sorted
1,2,3,3,5,6(sorted)........unsorted rest blocks
similarly extend it and finally u get all sorted list
thank u
i hope u understand
external sort
- Vincent August 19, 2012