You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />
IMPLEMENTATATION OF PRIORITY QUEUES:‐<br />
There are various way to implement a priority queues. These are:<br />
<strong>1.</strong> Using multiple queues, one for each priority.<br />
2. Using a linear linked list.<br />
3. Using a heap<br />
<strong>1.</strong> MULTIPLE QUEUES REPRESENTATION:<br />
In this representation, one of the queues is maintained for each priority<br />
number. In order to process an element of the priority queues, element from<br />
the first non‐empty highest priority number queues is accessed. In order to add<br />
a new element to the priority queues, the element is inserted in an appropriate<br />
queue for given priority number.<br />
Consider the priority queues as shown in figure.<br />
O1 O2 ……. Oi P1 P2 …….. pi<br />
1 1 ……. 1 2 2 …….. 2<br />
1=priority<br />
01=job identifier<br />
The priority queues of fig. can be visualized as three separated queues as shown<br />
in fig.1<br />
Priority1<br />
O1 O2 ……………….. oi<br />
Priority2<br />
P1 P2 …………….. pi<br />
In the figure1, jobs are always removed from the front of the queues.<br />
Now, whenever element are inserted, they are inserted in the end of one of the<br />
queues determined by their priority.<br />
2. LINKED LIST REPRESENTATION:‐<br />
To maintain the linked list in memory, we need two linear arrays denoted by<br />
INFO and LINK. Since the subscripts of the array INFO and LINK will be positive,<br />
therefore, we can choose NULL=0<br />
EXAMPLE:‐.<br />
Prepared By :<br />
Er. Harvinder Singh<br />
Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 150 ‐