![]() ![]() findMax() - Find maximum value in the queue.insert() - Inserts a new value into the queue.isEmpty() - Check whether queue is Empty.The following are the operations performed in a Max priority queue. For example, assume that we insert in the order 8, 3, 2 & 5 and they are removed in the order 8, 5, 3, 2. In a max priority queue, elements are inserted in the order in which they arrive the queue and the maximum value is always removed first from the queue. There are two types of priority queues they are as follows. Priority queue is a variant of a queue data structure in which insertion is performed in the order of arrival and deletion is performed based on the priority. This is what exactly done by the priority queue. Here, the average waiting time for all requests (R1, R2, R3 and R4) is (2+7+17+37)/4 ≈ 15 units of time.įrom the above two situations, it is very clear that the second method server can complete all four requests with very less time compared to the first method. R1 : 37 units of time (R1 must wait until R3 completes 17 units and R1 itself requires 20 units.R3 : 17 units of time (R3 must wait until R4 completes 7 units and R3 itself requires 10 units.R4 : 7 units of time (R4 must wait until R2 completes 2 units and R4 itself requires 5 units.Then serve R4 which has second minimum time (5 units) requirement and then serve R3 which has third minimum time (10 units) requirement and finally R1 is served which has maximum time (20 units) requirement. If we serve according to their required amount of time, first we serve R2 which has minimum time (2 units) requirement. Now, consider another way of serving these requests. ![]() That means, if we use a normal queue data structure to serve these requests the average waiting time for each request is 27 units of time. Here, the average waiting time for all requests (R1, R2, R3 and R4) is (20+22+32+37)/4 ≈ 27 units of time. R4 : 37 units of time (R4 must wait until R3 completes 35 units and R4 itself requires 5 units.R3 : 32 units of time (R3 must wait until R2 completes 22 units and R3 itself requires 10 units.R2 : 22 units of time (R2 must wait until R1 completes 20 units and R2 itself requires 2 units.Now, check to wait time of each request that to be completed. Assume four requests arrived at the queue in the order of R1, R2, R3 & R4 where R1 requires 20 units of time, R2 requires 2 units of time, R3 requires 10 units of time and R4 requires 5 units of time. This queue implementation may not be suitable for all applications.Ĭonsider a networking application where the server has to respond for requests from multiple clients using queue data structure. In the normal queue data structure, insertion is performed at the end of the queue and deletion is performed based on the FIFO principle. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |