time complexity - sorting a file containing huge amount of data -
consider file containing n words 1 word per line.the file big whole of connot read in memory @ 1 time.
ans: divide file k chunks.so size of each chunk x = n/k
read 1 chunk memory @ time , sort , write file.sort k chunks.
k way merge.
analying total time complexity. how can it?
time sorting each chunk = xlogx (assuming use quick sort)
time merging k chunks = klogk (is it??)
total time complexity =??
week @ analying time complexity
each chunk of size n/k , number of chunks k.
so, total time complexity
reading of n/k chunks + sorting each of chunks i.e., o( n/k klogk) + merging each [part] of k chunks o( nk ) + file writing.
so, io time + o(nlogk)
i learning these things too...so great if can analyze , correct me if im wrong here..
-pavan.
Comments
Post a Comment