# Recent questions tagged priority-queue 1
A priority queue is implemented as a Max-Heap. Initially, it has $5$ elements. The level-order traversal of the heap is: $10,8,5,3,2$. Two new elements $1$ and $7$ are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is $10,8,7,3,2,1,5$ $10,8,7,2,3,1,5$ $10,8,7,1,2,3,5$ $10,8,7,5,3,2,1$
1 vote
2
What is the worst case time of insert and extract- min in an implementation of a priority queue using an unsorted array? Assume that all insertions can be accommodated 1) θ(1) ,θ(n) 2) θ(n) ,θ(1) 3) θ(1) ,θ(1) 4) θ(n) ,θ(n)
3
Show how to implement a first-in, first-out queue with a priority queue. Show how to implement a stack with a priority queue.
4
Is priority queue work efficiently with sorted array than unsorted array and heap for insertion and deletion operation? Then why do we apply priority queue in heap specially
5
6
On other sources, it is given that we need to assign high priorities to newly inserted element in case of stack otherwise low priority to newly inserted element in case of queue. My doubt here is that shouldn't stack be implemented with max-heap priority queue and queue with min-heap priority queue keeping above assumption of assigning priorities to newly inserted element?
1 vote
7
Suppose Stack operations are implemented using Queue Operation. Push(x) and Pop() are stack operations whereas enqueue(x) and dequeue are Queue operations. Consider the code: pop() { return Q.dequeue(); } push(x) { n= Q.size(); //Q.size() returns the number of elements in the Queue ... () operation correctly (A) Q.enqueue(x) (B) Q.enqueue(Q.deqeue()) (C) Q.dequeue(Q.enqueue(x)) (D) Q.dequeue()
8
How to implement Priority queue using stack?What will be time complexity for Enqueue and Dequeue operations? Edit:- Updated the question clearly
1 vote
9
A priority queue is implemented as a max-heap. Initially, it has five elements. The levelorder traversal of the heap is as follows : 20, 18, 15, 13, 12 Two new elements 10' and 17' are inserted in the heap in that order. The level-order traversal of the heap after the insertion of the element is : 20, ... , 12, 10 20, 18, 17, 12, 13, 10, 15 20, 18, 17, 10, 12, 13, 15 20, 18, 17, 13, 12, 10, 15
A priority queue $Q$ is used to implement a stack that stores characters. PUSH (C) is implemented as INSERT $(Q, C, K)$ where $K$ is an appropriate integer key chosen by the implementation. POP is implemented as DELETEMIN$(Q)$. For a sequence of operations, the keys chosen are in non-increasing order non-decreasing order strictly increasing order strictly decreasing order