retagged by
2,049 views
2 votes
2 votes
Given "log n" sorted lists each of size "n/log n",what is the total time required to merge them into one single list.
retagged by

1 Answer

1 votes
1 votes

Before answering this question, Just boil down to a less easy question

Given n element, merge them into one sorted list using merge procedure.

we have n elements ,lets assume it at level 1(bottom level). Lets assume root to be at kth level.  we are merging 2 elements(each in one block)  of level 1 into single block on level 2. In this comparison & movement required it takes O(n) time. Now at level 2(second from bottom). Total number of elements will still be n But number of blocks reduced by half (if n is even it is exacty n/2. if odd then (n/2 )+1 nearly half). similarly at level 3, two of total n/2 Blocks merge together to form a single block so, at level 3 number of blocks will be (n/2)1/2 which is n/(2)level-1= n/22.  similarly at level 4, two of total (n/2)1/2 Blocks merge together to form a single block so, at level 4 number of blocks will be ((n/2)1/2)1/2 which is n/(2)level-1 = n/23. So on at level k which is root number of blocks will be n/2k-1  and we know at level k there will be only one block that is ROOT. so 

n/2k-1 = 1

i.e. n = 2k-1

so, log n = k -1= number of levels.=O(log n)

 

Just for movement and comparison from one level to another it takes O(n) time. So, what is total amount of time required to merge them to single list is

(Time to cross one level)*(no. Of total levels)
= n*log n

= O(n log n)

similarly, for your question,

BUT in your case, no. of total levels will be log log n so,

(Time to cross one level)*(no. Of total levels)
= n*log log n

= O(n log log n)

edited by

Related questions

0 votes
0 votes
3 answers
1
aditi19 asked Oct 6, 2018
1,149 views
what is the recurrence relation for merge sort?
1 votes
1 votes
1 answer
2
rahul sharma 5 asked Mar 9, 2018
1,320 views
Consider the modified merge sort where we divide array into 5 equal sub arrays instead if 2(as in standard merge sort).What is the time complexity if modified merge sort?...
1 votes
1 votes
0 answers
3
0 votes
0 votes
0 answers
4