0% found this document useful (0 votes)
9 views5 pages

Exp3 Priority Queue 24-25

Uploaded by

sujay.kamuni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Exp3 Priority Queue 24-25

Uploaded by

sujay.kamuni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

KJSCE/RAI/SY BTech/SEM III/DSA/2024-25

Experiment No. : 3

Title: Implementation of Static Priority Queue

A Constituent College of Somaiya Vidyavihar University


KJSCE/RAI/SY BTech/SEM III/DSA/2024-25

Batch: Roll No.: Experiment No.: 3

Aim: a) Write a menu driven program to implement a static priority queue supporting following
operations.
1. Create empty queue,
2. Insert an element on the queue,
3. Delete an element from the queue,
4. Display element with highest priority
5. Display all elements of the queue.

__________________________________________________________________________________

Resources Used: Turbo C/ C++ editor and compiler.

__________________________________________________________________________________

Theory:

Queue -
A queue is an ordered list in which insertion and deletion happens two different ends.
The insertion happens from the rear and the deletion takes place at the front. It works
with the FIFO concept i.e. first in first out.
Basic operations of Queue are enqueue, dequeue, isempty, etc.

Priority Queue –

A priority queue is a type of queue that arranges elements based on their priority
values. Elements with higher priority values are typically retrieved or removed before
elements with lower priority values. Each element has a priority value associated with
it. When we add an item, it is inserted in a position based on its priority value.

Properties of Priority Queue-

Priority Queue is an extension of the queue with the following properties.


 Every item has a priority associated with it.
 An element with high priority is dequeued before an element with low
priority.
 If two elements have the same priority, they are served according to their
order in the queue.

How is Priority assigned to the elements in a Priority Queue?

In a priority queue, generally, the value of an element is considered for assigning the
priority.
For example, the element with the highest value is assigned the highest priority and
the element with the lowest value is assigned the lowest priority. The reverse case can
also be used i.e., the element with the lowest value can be assigned the highest
priority. Also, the priority can be assigned according to our needs.

A Constituent College of Somaiya Vidyavihar University


KJSCE/RAI/SY BTech/SEM III/DSA/2024-25

Difference between Priority Queue and Normal Queue?

There is no priority attached to elements in a queue, the rule of first-in-first-out(FIFO)


is implemented whereas, in a priority queue, the elements have a priority. The
elements with higher priority are served first.

How to Implement Priority Queue?

Priority queue can be implemented using the following data structures:


Arrays
Linked list
Heap data structure
Binary search tree

A Constituent College of Somaiya Vidyavihar University


KJSCE/RAI/SY BTech/SEM III/DSA/2024-25

Methods :

Implement priority queue using array data structure

______________________________________________________________________________
Algorithm :
1. createQueue():
This method creates and empty queue

2. void enqueue(typedef val, typedef priority) :

This operation adds an item as per its priority. Before insert operation, ensure that
there is a room for the new item. If there is not enough room, then the queue is in an
‘Overflow’ state.

3. typedef dequeue() :

This operation removes the item with highest priority from the Queue and returns it to
the user. When the last item in the queue is deleted, it must be set to its empty state. If
dequeue is called when the queue is empty, then it’s in an ‘Underflow’ state.

4. typedef peek() :

This operation will return the item with highest priority.

5. void displayAll():

This operation will display all item present in the queue at that instance.

6. boolean isEmpty() :

This operation will check whether Queue is empty or not at a given instance. The
function will return
0 if Queue is not empty.
1 if Queue is empty.

7. boolean isFull() :

This operation will check whether Queue is full or not at a given instance. The
function will return
0 if Queue is not full.
1 if Queue is full.

Activity: students are expected to implement priority queue using array.

NOTE : All functions should be able to handle boundary(exceptional) conditions.

_________________________________________________________________________________

A Constituent College of Somaiya Vidyavihar University


KJSCE/RAI/SY BTech/SEM III/DSA/2024-25

Results: A program implementing solution depicting the correct behaviour of priority queues and
capable of handling all possible exceptional conditions and the same is reflecting clearly in the
output.

_________________________________________________________________________________

Outcome:

Conclusion:

Grade: AA / AB / BB / BC / CC / CD /DD:
______________________________________________________________________________
Signature of faculty in-charge with date :

References:

Books/ Journals/ Websites:

Sr. Name/s of Author/s Title of Book Publisher Edition/Year


No
1 Aaron M Tanenbaum Data structure Using C Pearson 12th/e, 2013
Yedidyah Langsam
Moshe J Augentstein
2 Ellis Horowitz, Sartaj Fundamentals Of Data University Press 02nd/e,
Sahni, Susan Structures In C 2018
Anderson-Freed
3 Michael T Goodrich Data Structure and Wiley 01st/e,
Roberto Tamassia Algorithm in C++ 2007
David Mount
4 Richard F. Gilberg & Data Structures A CENGAGE 02nd/e, 2007
Behrouz A. Forouzan Pseudocode Approach Learning
with C
5 T.H.Coreman , Introduction to algorithms Prentice Hall India 3rd/e, 2010
C.E. Leiserson,R.L. Publication
Rivest, and C. Stein
6 Aaron M Tanenbaum Data structure Using C Pearson 12th/e, 2013
Yedidyah Langsam
Moshe J Augentstein

A Constituent College of Somaiya Vidyavihar University

You might also like