Question

In: Computer Science

One of the benefits of having our data structures be generalized to hold any type of...

One of the benefits of having our data structures be generalized to hold any type of data is that we can have data structures store instances of data structures. As we mentioned in class, a priority queue is a queue where entries are added (enqueued) according to their priority level (and in order when priority is tied). So the entry with the highest priority that was added to the priority queue the earliest would be at the front and would be the entry that is removed (dequeued).

Given that entries with the same priority will have to be organized in the order they were enqueued (first-in, first out), one possible option is to create a PriorityQueue that holds Queue objects. At the top level, the PriorityQueue can organize entries according to priority level and ensure that the separate priority groups are maintained in their proper order. At the next level, each component Queue would be responsible for all of the entries with the same priority level, and can maintain them in the order in which they were enqueued.

For this problem, assume that there are only 5 priority levels (1 = very low; 2 = low;
3 = medium; 4 = high; 5 = very high). Give a detailed description of how you could implement the PriorityQueue as described above. Your answer should include:

  •  How the top-level organization would work.

  •  What properties your class would need.

  •  A short description of how each of the three main queue operations (enqueue, dequeue,

    and getFront) would work.

Solutions

Expert Solution

Priority queue is the extension of normal queue.

> Every item is associated with the priority.

> The item is with the highest priority is dequeued first than the the item with the lowest priority.

> If the two items are having the same priority, then according to the items in the queue they are dequeued.

Coming to the elements i.e characters with the highest ASCII value will be dequeued first than the elements with the lowest ASCII value.

There are three types of priority queue operations are:

> insert()

> GetHighestpriority()

> deleteHighestpriority()  

Deleting the items from the list.

Inserting the elements into the queue, thw element can be inserted at the last of the position which is the order of O(1).

These priority queues are implemented using the Heaps. Heaps only gerally used to implement the priority queues.

Applications of Priority Queue:
1) CPU Scheduling algorithm.
2) Graph algorithms like Dijkstra’s shortest path algorithm, Prim’s Minimum Spanning Tree, etc
3) All queue applications where priority property is involved.

A priority queue is a concept like "a list" or "a map"; just as a list can be implemented with a linked list or an array, a priority queue can be implemented with a heap or a variety of other methods such as an unordered array.

----Properties of priority class needed are:

> add() - Inserts the elements in the priority queue.

> clear() - It clears all the elements in the priority queue.

> comparator() - It returns the comparator used to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements.

> contains() - It returns true if there are no elements in the priority queue.

> iterator() - It returns an iterator over the elements in this queue.

> remove() - It removes all the elements in the priority queue.

> splititerator() - Creates the late- binding over the elements in the priority queue.

These are the some of the methods in the priority class java.

The operations of priority queue are :

> Enqueue

> Dequeue

In the queue only two operations are allowed enqueue and dequeue. Enqueue means to insert an item into the back of the queue, dequeue means removing the front item.

In Enqueue, Queues maintain two data pointers, front and rear. Therefore, its operations are comparatively difficult to implement than that of stacks.

In Dequeue, Accessing data from the queue is a process of two tasks − access the data where front is pointing and remove the data after access.

These are the operations in the queue.

These priority queues are implemented in the many different languages like python, java, C, C++.


Related Solutions

PLEASE NO USE OF LINKED LIST OR ARRAYS(USE CHARACTER POINTERS INSTEAD) TO HOLD DATA STRUCTURES This...
PLEASE NO USE OF LINKED LIST OR ARRAYS(USE CHARACTER POINTERS INSTEAD) TO HOLD DATA STRUCTURES This lab, for which you may work in groups of two, will require you to use a C structure to hold a record of any kind of data, i.e., address book, library of books as with chapter 14, etc. These records will be held in dynamic memory using memory allocation (malloc) to create new memory and the function (free) to release memory created via (malloc)....
For each type of the four market structures, list one type of market/brand that satisfies or...
For each type of the four market structures, list one type of market/brand that satisfies or as closely satisfies this market structure. Provide reasoning for your choices. (Be sure to provide one example for each structure type.) Originality will be considered in grading Principles of Microeconomics.
For each type of the four market structures, list one type of market/brand that satisfies or...
For each type of the four market structures, list one type of market/brand that satisfies or as closely satisfies this market structure. Provide reasoning for your choices. (Be sure to provide one example for each structure type.) Originality will be considered in grading
swift language declare a Swift array variable that can hold instances of any class type
swift language declare a Swift array variable that can hold instances of any class type
9. Which type of risk is NOT important when considering the governance structures of organizations(or any...
9. Which type of risk is NOT important when considering the governance structures of organizations(or any other type of organiational form)? a. Financial Risk B. Collaborative Risk C. Exchange Rate Risk D. Bounded rationally risk
Multiple - Choice: What are possible benefits to use a captive (can be any type of...
Multiple - Choice: What are possible benefits to use a captive (can be any type of captive)? a. Completely transfer risk to the fronting company b. Create a source of profit for the parent c. Design and customize the company's own risk financing programs d. Manage risk using internal sources which are cheaper than external funds e. Peer pressure to keep up with loss control which ultimately benefits the business
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the...
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the question above in a few sentences.
Well our Data Structures and Algorithms professor had the incorrect date set for this assignment (was...
Well our Data Structures and Algorithms professor had the incorrect date set for this assignment (was November 7, 2019 and now is October 7, 2019) so I was putting it off until the end of this month, now I have two days to complete it which is going to be near impossible with the assignments I have for C Programming, Calculus II and Anthropology also all due on Monday, so I need some help. I have the general outline for...
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure...
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure you don't just give me a list but a few sentences instead just answering it.
Select an industry that belongs to any one of the four market structures – perfect competition,...
Select an industry that belongs to any one of the four market structures – perfect competition, monopoly, monopolistic competition or oligopoly. Explain why you think it belongs to your identified market structure based on the market characteristics number or firms, type of product, entry/exit barriers, market power Explain your reasoning and provide the rationale for your answer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT