Applications of queues ii
-
Upload
techmx -
Category
Technology
-
view
6.384 -
download
1
description
Transcript of Applications of queues ii
![Page 1: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/1.jpg)
Twitter: @THATlittleJOKE
APPLICATIONS OF QUEUES - II
![Page 2: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/2.jpg)
Twitter: @THATlittleJOKE
Linear Queues.
TYPES OF QUEUES
Priority Queues.
Circular Queues.
Deque.
1.
2.
3.
4.
![Page 3: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/3.jpg)
Twitter: @THATlittleJOKE
• A priority queue is a queue in which insertion or deletion of items from any position in the queue are done based on some property (such as priority of task).– The main objective is to serve first the
items with higher priority.
DEQUE
PRIORITY QUEUE
![Page 4: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/4.jpg)
Twitter: @THATlittleJOKE
METHOD 1 :
• A common method of implementation of a priority queue is to open as many queues as there are priority factors.
• A low priority queue will be operated for deletion only when all its high priority predecessors are empty.
METHOD 2 :
METHODS OF IMPLEMENTATION
![Page 5: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/5.jpg)
Twitter: @THATlittleJOKE
• ENQUEUEING
1. Each distinct priority will have a separate queue to have its respective elements.
2. Thus when enqueing an item, we need both the item and its priority to enqueue it in the respective queue.
3. The items will be enqueued into the respective queue based on their priority.
IMPLEMENTATIONMETHOD 1:
![Page 6: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/6.jpg)
Twitter: @THATlittleJOKE
• DEQUEUEING
Cont.,METHOD 1:
1.A dequeue command checks for items in the queue with the highest priority.
2.Once it is found non-empty, the item from it will be dequeued based on the FIFO concept.
3.If the queue is empty, it moves to the next non-empty queue in the order and performs the operation.
![Page 7: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/7.jpg)
Twitter: @THATlittleJOKE
• The “Queue Overflow” warning will be thrown only when all the queues are found full.
• The “Queue Underflow” warning will be thrown only when all the queues are found empty.
• The implementation depends upon the application (TRADE OFF)
Cont.,METHOD 1:
![Page 8: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/8.jpg)
Twitter: @THATlittleJOKE
APPLICATIONSMETHOD 1:
1. O.S Job Scheduling.
2.Sharing a single runway of an airport for both landing and take-off of flights.
![Page 9: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/9.jpg)
Twitter: @THATlittleJOKE
APPLICATIONO.S JOB SCHEDULING:
A B C D
X Y Z
M N O
Q1-4
Q2-2
Q3-1
Q
![Page 10: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/10.jpg)
Twitter: @THATlittleJOKE
APPLICATIONS
2.Sharing a single runway of an airport for both landing and take-off of flights.
![Page 11: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/11.jpg)
Twitter: @THATlittleJOKE
METHOD 1 :
• A common method of implementation of a priority queue is to open as many queues as there are priority factors.
• A low priority queue will be operated for deletion only when all its high priority predecessors are empty.
• Another method of implementation could be to sort the elements in the queue according to the descending order of priorities every time an insertion takes place.
• The top priority element at the head of the queue is the one to be deleted.
METHOD 2 :
METHODS OF IMPLEMENTATION
![Page 12: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/12.jpg)
Twitter: @THATlittleJOKE
• Despite of having separate queues for every distinct priority, here we use only one queue.
• We store the items in the queue in the descending order of priority, thus making it possible with a single queue.
IMPLEMENTATIONMETHOD 2:
![Page 13: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/13.jpg)
Twitter: @THATlittleJOKE
• ENQUEUE:
• Here too, the priority of the item is also needed to enqueue the item.
• The items are enqueued in the queue based on their priorities.
• The items are enqueued at the right place so that the queue retains its descending order.
IMPLEMENTATIONMETHOD 2:
![Page 14: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/14.jpg)
Twitter: @THATlittleJOKE
• DEQUEUE:
• The dequeue operation is performed the same method as done in the linear queue.
• As it is the item with the highest priority which is at the front end, it is obviously the element with the highest priority that is being pushed out.
IMPLEMENTATIONMETHOD 2:
![Page 15: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/15.jpg)
Twitter: @THATlittleJOKE
• The “Queue Overflow” warning will be thrown when the queue is found full (physically or procedurally).
• The “Queue Underflow” warning will be thrown only when the queue is empty.
IMPLEMENTATIONMETHOD 2:
![Page 16: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/16.jpg)
Twitter: @THATlittleJOKE
APPLICATIONSMETHOD 2:
1. Sorting.
2.O.S Job sharing .
![Page 17: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/17.jpg)
Twitter: @THATlittleJOKE
APPLICATIONSORTING:
{(A,4),(B,2),(C,5),(D,1),(E,3)}
A BC DE
![Page 18: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/18.jpg)
Twitter: @THATlittleJOKE
METHOD 1: Doesn’t incur any expensive operation (queue
movement). METHOD 2:
Consumes lesser memory.
ADVANTAGES
METHOD 1: Consumes more memory.
METHOD 2:Incurs any expensive operation (queue movement).
DISADVANTAGES
Each queue can be treated as a linear (linear or circular) queueHence the usage depends on the application and its needs (TRADE OFF).
![Page 19: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/19.jpg)
Twitter: @THATlittleJOKE
A priority queue is a queue in which insertion or deletion of items from any position in the queue are done based on some property (such as priority of task).
The main objective is to serve first the items with higher priority.
A deque (Double Ended Queue) is a linear list in which all insertions and deletions are made at the end of the list. DEQUE
PRIORITY QUEUE
![Page 20: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/20.jpg)
Twitter: @THATlittleJOKE
A deque is therefore more general than a queue and is a sort of FLIFLO (first in last in or first out last out). Two way insertion or deletion.
Thus while one speaks of the top or bottom of a stack, or front or rear of a queue, one refers to the right end or left end of a deque.
A deque has two variants: input restricted deque and output restricted deque.
DEQUE
![Page 21: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/21.jpg)
Twitter: @THATlittleJOKE
TYPE 1 : INPUT RESTRICTED DEQUE
An input restricted deque is one where insertions are allowed at one end only while deletions are allowed at both ends.
An output restricted deque allows insertions at both ends of the deque but permits deletions only at one end.
TYPE 2 : OUTPUT RESTRICTED DEQUE
METHODS OF IMPLEMENTATION
![Page 22: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/22.jpg)
Twitter: @THATlittleJOKE
DEQUE
IMPLEMENTATION
![Page 23: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/23.jpg)
Twitter: @THATlittleJOKE
DEQUE
APPLICATION
![Page 24: Applications of queues ii](https://reader036.fdocuments.net/reader036/viewer/2022062617/54c17b344a79596d308b460e/html5/thumbnails/24.jpg)
Twitter: @THATlittleJOKE
Thank You…..
Queries..??