Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

PRIORITY QUEUE

Guided by: Ms. Sini Kurian

Presented by:
Amrith Krishna,
S4 CSE-A
FISAT
What is Data Structure ?

Organization of data needed to


solve the problem
21
april Mr. V K Adarsh
10:45
20
april Mr. Amarnath Raja
9:00
20
april Mr. Vimal Joseph
10:45

ICE-FOSS Dilemma
21
april Dr. Sethumadhavan
9:00
20
april Mr. Pramode C E
21 1:30
april Mr. Ciju Rajan
1:45
20 21
april Mr. Amarnath Raja april Dr. Sethumadhavan
9:00 9:00

20 21
april Mr. Vimal Joseph april Mr. V K Adarsh
10:45 10:45

20 21
april Mr. Pramode C E april Mr. Ciju Rajan
1:30 1:45
A priority Queue consists of entries, each
of which contains key called the priority of
the entry and a value, the data part.
20
april Mr. Amarnath Raja
9:00

Key Data
A Closer Look at

Priority Queues
Elements with
Element of higher
same priority are
priority is
Does not follow processed in
processed before
FIFO according to the
any element of
order in which they
lower priority
were added
Ins
erti
on

Processes
on
Priority
Queue

De
leti
on

LIFO FIFO Key


Insertion
Deletion 1 Data 1
Front
9 Data 5 2 Data 2

2 Data 6 8 Data 3

10 Data 4
Rear
Implementing Priority Queues
Simple/Circular
Simple/Circular
Array
Multi-queue

Array
Multi-queue
Implementation
Implementation

Ways

Heap
HeapTree
Linked List
Linked List
Doubly
Doubly

Tree
Algorithm (Insert an element)

1. Start
2. Read data with priority p
3. Front = prior[p][0]
4. Rear=prior[p][0] 4a525a
5. If(front=rear= -1) goto step 6 else 10
6. Set front=rear=0
7. Set pqueue[p][rear]=data
8. Prior[p][0]=front
9. Prior[p][1]=rear
Algorithm (Insert an element)

10. if(front=(rear+1)mod n)
print overflow and exit
11. rear=(rear+1)mod n
12. Set pqueue[p][rear]=data
4a525a

13. prior[p][1]=rear
14. exit
1 2 3 4 5 6 7 8 9 10 11 12 13

Front Rear N p

Prior pqueue
0 1 0 1 2 3 4 5
0 -1 -1 0
1 -1 -1 1
2 -1 -1 2
3 -1 -1 3
4 -1 -1 4
5 -1 -1 5
Algorithm (Delete an element)

1. Start
2. Set p=0
3. If p<max_prin goto step 4 else print“invalid
priority” & exit. 4a525a
4. Set front=prior[p][0]
5. Set rear=prior[p][1]
6. If(front=rear=-1) goto 7 else 8
7. P++ & goto step 3
8. Print pqueue[front]
Algorithm (Insert an element)

9.if(front=rear) goto 10 else 11


10. Set prior[p][0]=prior[p][1]=-1 goto 12
11. Set prior[p][0]=(front+1)mod n
12. Stop 4a525a
Thank You

You might also like