Question

3. Some circular queue implementations use the mod operator % in enqueue and dequeue operations. Explain why this is inefficient. 4. If a queue is implemented using a singly linked list with a head and tail pointer, you should always insert at the tail and remove from the head. Explain why this is so. 5. What is a Priority Queue, and how does it differ from a standard queue? 6. Priority Queues are almost always implemented with an ordered data structure. Why?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 3:

A circluar queue is like a circle which do not have isolated front and rear ends or we can say front and rear ends are merged together in order to form a circle. Suppose we have normal linear empty queue of length 5, so intially both front and rear end will be on index 0, now as soon as we start inserting elements in queue rear end starts moving by step 1. If rear end reaches at the max length of queue i.e; at index 4, then queue is full. If we pop element from full queue then index 0 will get empty and now again we can insert a element at index 0 because we have made over queue circular that's why we can jump on index 0 from index 4 but to achieve this we need to take mod (%) of (rear+1) with size of queue, in order to get next empty index i.e rear = (rear+1)%size

---------------------------------------------------------------------------------

Answer 4:

Because queue is FIFO data structure that means first in first out. To achieve this property while implementing queue as singly linked list we insert element from tail and remove element from head.

----------------------------------------------------------------------------------

Answer 5:

A priority queue is like a normal queue but there is one extra property in it which is "priority" i.e; each elements in priority queue has it's own priority value and element with highest priority is served first before low priority element. Priority queue data structure is used in mostly process scheduling algorithm.

-----------------------------------------------------------------------------

Answer 6:

Because to choose elements based on their priorities they must arranged in some order. For example, Binary search tree where left node is smaller than root and right node is greater than root. So if elements are set in any order then we can decide priority of any elements i.e; we will get know what we should pick next.

Add a comment
Know the answer?
Add Answer to:
3. Some circular queue implementations use the mod operator % in enqueue and dequeue operations. Explain...
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
  • Suppose we want to implement a circular queue using an array that has an initial capacity...

    Suppose we want to implement a circular queue using an array that has an initial capacity (maximum number of elements) MAX. A circular queue is like a regular queue except that elements can be enqueued or dequeued by wrapping around it. Assume we enqueue on the tail and dequeue from the head. An example circular queue with sample operations is shown below: head head tail head tail tail head Enqueue(9) a) Write a program in C that implements this circular...

  • Questions; What a priority queue is. How to implement the DEQUEUE, ENQUEUE, IS-EMPTY, and IS-FULL operations...

    Questions; What a priority queue is. How to implement the DEQUEUE, ENQUEUE, IS-EMPTY, and IS-FULL operations for priority queues using max-heaps. How these algorithms work andtheir run times. BUILD-MAX-HEAP   HEAP-EXTRACT-MAX   HEAP-INCREASE-KEY   HEAP-MAXIMUM   HEAPSORT   INSERTION-SORT   LEFT   MAX-HEAP-INSERT   MAX-HEAPIFY   PARENT   RIGHT

  • [Java] Efficiency Comparison of two Implemented Queues : Circular Array Queue and SSQueue and its enqueue...

    [Java] Efficiency Comparison of two Implemented Queues : Circular Array Queue and SSQueue and its enqueue and dequeue operations Need to write a program that compares the efficiency of the queue implementations. To do so, you need to find and compare the running times of 1 the following two scenarios for both queue implementations: 3.1 Scenario 1: Alternating Sequence of Enqueues and Dequeues For every n ∈ {20, 50, 100, 1000, 10000, 100000, 1000000}, do the following: 1. long startTime...

  • solving using C. Use a singly linked list to implement a priority queue with two operations:...

    solving using C. Use a singly linked list to implement a priority queue with two operations: enqueue and dequeue. Each node contains an integer value, a priority, and a pointer to the next node. The priority is a value between 1- 10 (where 10 is the highest priority). When a value is added to the queue, it is added with a value and priority. When a value is removed from the priority queue, the first element with the highest priority...

  • Template Dequeue Class (C++ ) In this assignment, we will use a given test menu for the template ...

    Template Dequeue Class (C++ ) In this assignment, we will use a given test menu for the template Deque Class (a Linked List based Double Ended Queue, Deque) that you have put together. Starter testDeque.cpp which contains: Timer class holder (you need to go through the LearnCpp Ch15 and import it in) Node class Deque class specification (you need to fill out the definition) here is the testDeque.cpp code: // C++ implementation of doubly linked list Deque doubly linked list...

  • 1. State and explain the definition of big-O. 2. Explain why we use big-O to compare...

    1. State and explain the definition of big-O. 2. Explain why we use big-O to compare algorithms. 3. Explain why binary search runs in O(log n) time. 4. Under what conditions is it possible to sort a list in less than O(nlog n) time? 5. List and explain the worst-case and average-case running times for each Vector method below: (a) insert(iterator here, Object item) (b) insertAtHead (c) insertAtTail (aka push back) (d) get(iterator here) (e) get(index i) (f) remove(iterator here)...

  • Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your...

    Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your own Array-Based Stack (ABS) and Array-Based Queue (ABQ). A stack is a linear data structure which follows the Last-In, First-Out (LIFO) property. LIFO means that the data most recently added is the first data to be removed. (Imagine a stack of books, or a stack of papers on a desk—the first one to be removed is the last one placed on top.) A queue...

  • Simple test in text: int main() { Deque dq1; cout << dq1.empty() << " - 1"...

    Simple test in text: int main() { Deque dq1; cout << dq1.empty() << " - 1" << endl; dq1.insertFront(42); dq1.insertBack(216); cout << dq1.peekFront() << " - 42" << endl; cout << dq1.peekBack() << " - 216" << endl; cout << dq1.size() << " - 2" << endl; Deque dq2(dq1); Deque dq3; dq3 = dq1; cout << dq1.removeFront() << " - 42" << endl; cout << dq1.removeBack() << " - 216" << endl; cout << dq2.peekFront() << " - 42" <<...

  • Template Deque Class (C++) In this assignment, we will use a given test menu for the template Deq...

    Template Deque Class (C++) In this assignment, we will use a given test menu for the template Deque Class (a Linked List based Double Ended Queue, Deque) that you have put together. Recommended Steps testDeque.cpp : // C++ implementation of doubly linked list Deque doubly linked list #include <bits/stdc++.h> using namespace std; class Timer { // To replace with the full timer class definition // inside this folder: LearnCpp9_18_timeSortArray.cpp }; // Node of a doubly linked list template<class T> class...

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