Question

5. Consider a priority queue of strings with an integer priority. The queue us implemented as a min heap using a 0-based arra

0 0
Add a comment Improve this question Transcribed image text
Answer #1

given

1) priority_queue<string,int> pq;

2)pq.push("start",10);

3)pq.push("Stop",1);

4) pq.push("pause",1);

5) pq.push("rewind",1);

6)pq.pop();

7)pq.push("stop",10);

8)pq.pop();

Output of the above program:

rewind,1

start,10

stop,10

//here initially the queue is sorted according to the integer priority after the line six. Then after the first pop() one of the least integral element is removed and then again one more element is inserted.

then after the final pop() again the one with least integral element is removed.

Add a comment
Know the answer?
Add Answer to:
5. Consider a priority queue of strings with an integer priority. The queue us implemented as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In class, we discussed the priority queue (PQ) ADT implemented using min-heap. In a min-heap, the...

    In class, we discussed the priority queue (PQ) ADT implemented using min-heap. In a min-heap, the element of the heap with the smallest key is the root of the binary tree. On the other hand, a max-heap has as root the element with the biggest key, and the relationship between the keys of a node and its parent is reversed of that of a min-heap. We also discussed an array-based implementation of heaps. In this assignment, your task is to...

  • Indicate the time efficiency classes of the three main operations of the priority queue implemented as...

    Indicate the time efficiency classes of the three main operations of the priority queue implemented as a. an unsorted array. b. a sorted array. c. a binary search tree. d. an AVL tree. e. a heap.

  • The tree diagram below depicts a heap being used to implement a priority queue. Enqueue the...

    The tree diagram below depicts a heap being used to implement a priority queue. Enqueue the value 6 onto the priority queue, then execute a dequeue. After those two operations have been completed, what does the underlying array look like? List the elements in the resulting heap in the order in which they appear in the array, from left to right.

  • 1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show...

    1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show the Linked List after the following commands are executed: Stack myStack = new Stack(); myStack.push(20); myStack.push(40); myStack.pop(); myStack.push(60); myStack.push(80); 2)If the same commands were used but the Stack was implemented with an Array with maximum size of 10, show what the array would look like after all these commands are executed. Assume O(1) implementation of push and pop here as well. 3)Given a Queue...

  • Consider the following functions that implement the dequeue operation for a priority queue that is implemented...

    Consider the following functions that implement the dequeue operation for a priority queue that is implemented with a heap. int[] pQueue; int length; int dequeue() { int node = 1; int value = pQueue[--length]; int maxValue = pQueue[node]; int location = sift(node * 2, value); pQueue[location] = value; return maxValue; } int sift(int node, int value) { if (node <= length) { if (node < length && pQueue[node] < pQueue[node + 1]) node++; if (value < pQueue[node]) { pQueue[node /...

  • Using C++, data structures, C++ STL, inputs and expected outputs are shown below. Max Heap Heap...

    Using C++, data structures, C++ STL, inputs and expected outputs are shown below. Max Heap Heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either > (in a max heap) or s (in a min heap) the key of C. The node at the "top" of the heap (with no parents) is called the root node. In binary-tree based heap, it...

  • Suppose the following operations are performed on a queue containing integers. Create an empty queue Push...

    Suppose the following operations are performed on a queue containing integers. Create an empty queue Push 1 Push 2 Push 3 Pop Push 4 Push 5 Pop Now do the following: a. Draw a sketch of a doubly linked-list based queue after steps 1-4. b. Draw a sketch of a doubly linked-list based queue after all steps 1-8. c. Draw a sketch of a circular array-based queue with capacity 6 after steps 1-4. Specify f, t, and size after each...

  • Write a program in Java to implement the max-priority queue using max-heap data structure. Implement the...

    Write a program in Java to implement the max-priority queue using max-heap data structure. Implement the max-heap data structure using an integer array of 10 cells. (Do not use Java in-built PriorityQueue class.) [In a max-heap, the root node and the intermediate node vales are always greater than their children.] First, take 10 integer values from the user and insert them in the max-priority queue. Then print the elements of the queue. After that, delete two elements from the queue...

  • (ii) [6 marks] Assume that we have an empty stack S and an empty queue Q....

    (ii) [6 marks] Assume that we have an empty stack S and an empty queue Q. Given a series of stack operations on S as below: Push(S,10), Push(S, 7), Push(S, 23), Pop(S), Push(S, 9), Pop(S), Pop(S) Output the element returned by each Pop operation. Given a series of queue operations on Q as below: Enqueue(0,10),Enqueue(Q,20), Enqueue(0,33), Dequeue(Q), Enqueue(Q,55), Dequeue(Q), Dequeue(Q) Output the element returned by each Dequeue operation. (iii) [8 marks] Given an empty binary search tree T, draw the...

  • 14 18 11 10 19 16 23 28 15 21 Again, recall that in a Java...

    14 18 11 10 19 16 23 28 15 21 Again, recall that in a Java program, a binary heap is stored as an array with the first element in position [O] unused, in order to simplify the swim() and sink() operations. Let us denote the unused element of the array with the symbol "#". Therefore, the above complete binary tree will be represented by the following array: T[ 0..13 ] = [ #, 5, 6, 7, 14, 18, 11,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT