DSA Experiment No.10
DSA Experiment No.10
Experiment No.10
OBJECTIVES:
1. To understand priority queue data structure.
2. To understand practical implementation and usage of queue linear data structures
OUTCOMES:
1. Apply and analyze appropriate data structure to solve the real time problems using priority
queue
PRE-REQUISITE:
1. Knowledge of C++ programming
2. Knowledge of 2D-Array, structures
THEORY:
A Queue is a linear structure which follows a particular order in which the operations are
performed. The order is First In First Out (FIFO). The difference between stacks and queues is in
removing. In a stack we remove the item the most recently added; in a queue, we remove the item
the least recently added.
A queue in which we are able to insert and remove items from any position based on some
property (such as priority of the task to be processed) is often referred as priority queue. Fig 1
represents a priority queue of jobs waiting to use a computer.
Priority Queue is an extension of queue with following properties.
Using Array: A simple implementation is to use array of following structure. insert() opera-
tion can be implemented by adding an item at end of array in O(1) time. getHighestPriority()
operation can be implemented by linearly searching the highest priority item in array. This
operation takes O(n) time.
Heap is generally preferred for priority queue implementation because heaps provide better
performance compared arrays or linked list.
1) CPU Scheduling
2) Graph algorithms like Dijkstra’s shortest path algorithm, Prim’s Minimum Spanning Tree,
etc
QUESTIONS: