edited by
1,319 views
2 votes
2 votes

Suppose there are $\log_n$ sorted lists of $n \log_n$ element each. The time complexity of producing a sorted list  of all these elements is (use heap data structure)

  1. $O (n \log \log_n)$
  2. $\theta (n \log_n)$
  3. $\Omega (n \log_n)$
  4. $\Omega (n^{3/2})$
edited by

2 Answers

1 votes
1 votes
Since total elements are logn * n logn = n(logn)^2 . heapify procedure take O(n (logn)^2) . not in option so Omega (nlogn)
0 votes
0 votes

We can merge arrays in O($nk\log k$) time using Min Heap. Following is detailed algorithm.

1. Create an output array of size n*k.
2. Create a min heap of size k and insert 1st element in all the arrays into a the heap
3. Repeat following steps n*k times.
     a) Get minimum element from heap (minimum is always at root) and store it in output array.
     b) Replace heap root with next element from the array from which the element is extracted. If the array doesn’t have any more elements, then replace root with infinite. After replacing the root, heapify the tree.

 

Time complexity of producing a sorted list of all these element=O($nk\log k$)

Here K= $\log n$

n=$n\log n$

Time complexity of producing a sorted list of all these element=

O($nk\log k$)=O$(n\log n\log n\log \log n)$

 

Hence,none of these.

 

edited by
Answer:

Related questions

1 votes
1 votes
3 answers
1
go_editor asked Jul 12, 2016
1,230 views
Let $T(n)$ be a function defined by $T(n) =1$ and $T(n)=2T (n/2) + \sqrt{n}$, which of the following is true?$T(n) = O(\sqrt{n})$$T(n) = O(\log_2 n)$$T(n) = O(n)$$T(n) = ...
0 votes
0 votes
1 answer
2
Sanjay Sharma asked May 9, 2016
1,799 views
The time complexities of some standard graph algorithms are given. Match each algorithm with its time complexity ? ($n$ and $m$ are no. of nodes and edges respectively)$\...
1 votes
1 votes
1 answer
4
go_editor asked Jul 13, 2016
2,994 views
A* algorithm is guaranteed to find an optimal solution ifh’ is always 0g is always 1h’ never overestimates hh’ never underestimates h