GATE | GATE MOCK 2017 | Question 40
Consider n elements that are equally distributed in k stacks. In each stack, elements of it are arranged in ascending order (min is at the top in each of the stack and then increasing downwards).
Given a queue of size n in which we have to put all n elements in increasing order. What will be the time complexity of the best known algorithm?
(A) O(n logk)
(B) O(nk)
(C) O(n2)
(D) O(k2)
Answer: (A)
Explanation:
In nlogk it can be done by creating a min heap of size k and adding all the top – elements of all the stacks. After extracting the min , add the next element from the stack from which we have got our 1st minimum.
Time Complexity = O(k) (For Creating Heap of size k) + (n-k)log k (Insertions into the heap).
Quiz of this Question
Recommended Posts:
- GATE | GATE MOCK 2017 | Question 55
- GATE | GATE 2017 Mock | Question 64
- GATE | GATE 2017 Mock | Question 65
- GATE | GATE 2017 MOCK II | Question 1
- GATE | GATE 2017 MOCK II | Question 2
- GATE | GATE 2017 MOCK II | Question 3
- GATE | GATE 2017 MOCK II | Question 4
- GATE | GATE 2017 MOCK II | Question 5
- GATE | GATE 2017 MOCK II | Question 6
- GATE | GATE MOCK 2017 | Question 56
- GATE | GATE MOCK 2017 | Question 58
- GATE | GATE MOCK 2017 | Question 59
- GATE | GATE MOCK 2017 | Question 60
- GATE | GATE MOCK 2017 | Question 61
- GATE | GATE MOCK 2017 | Question 62



