0% found this document useful (0 votes)
38 views24 pages

Priority Queue Presentation

The presentation by the Cyber Knights provides an in-depth exploration of Priority Queues, covering their abstract data type (ADT), operations, implementation strategies, and various applications. Key operations such as enqueue, dequeue, and display are discussed along with their pseudocode, advantages, and limitations. The document emphasizes the importance of priority queues in task scheduling, network routing, and real-time processing.

Uploaded by

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

Priority Queue Presentation

The presentation by the Cyber Knights provides an in-depth exploration of Priority Queues, covering their abstract data type (ADT), operations, implementation strategies, and various applications. Key operations such as enqueue, dequeue, and display are discussed along with their pseudocode, advantages, and limitations. The document emphasizes the importance of priority queues in task scheduling, network routing, and real-time processing.

Uploaded by

masapusriram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Priority Queue: Team

Cyber Knights
Presentation
Cyber Knights present a deep dive into Priority Queues. We
will explore their ADT, operations, implementation, and
applications. This presentation covers core concepts and
practical uses.

Team Members:

P.Varun Teja, P.Sri Harsha Vardhan, M.Sreeram, M.Harinadh,


and D.Chaitanya Anirudh.
CONTENTS
• Introduction

• Core concepts

• Priority Queue Operations Pseudocode

• Implementation

• Priority Queue Applications

• Advantages and Limitations


INTRODUCTION
PART 01
Understanding Priority Queues

Queues vs. Priority Queues Real-World Uses

Standard queues use FIFO. Priority Queues Task scheduling ensures critical processes run
dequeue based on element priority. first. Hospital triage prioritizes patients by
severity.
• FIFO (First-In, First-Out) for queues • Task Scheduling
• Priority-based for Priority Queues • Hospital Triage
PRIORITY QUEUE
Priority Queue ADT
Data
A set of elements. Each element has an associated priority.

Operations
Basic functions manage the queue's state. These are insert, peek
and extractMax/Min.

Priority Assignment
Rules define the range and meaning of priority values.

Ordering
Elements are arranged by priority.
CORE CONCEPTS
PART 02
Priority Queue Operations
enqueue(element, priority)
Adds an element with its priority.

peek()
Returns the highest priority element.

dequeue()
Removes highest priority element.

isEmpty()
Checks if the queue is empty.

Display()
Displays the elements in the queue.

These fundamental operations allow for efficient management of prioritized data.


Enqueue Operation
Find Insertion Point
Identify correct spot using priority.

Shift Elements
If needed, shift elements to make space.

Place New Element


Insert new element in the calculated spot.

Careful insertion maintains heap properties and ensures


efficient priority management.
PSEUDOCODE FOR ENQUEUE OPERATION
// Function to insert an element with priority (Enqueue)

void enqueue(PriorityQueue *pq, int value, int priority)

if (isFull(pq))

printf("Queue is Full! Cannot insert %d\n", value);

return;

// Insert at the correct position based on priority

int i = pq->count - 1;

while (i >= 0 && pq->items[i].priority > priority)

pq->items[i + 1] = pq->items[i];

i--;

pq->items[i + 1].data = value;

pq->items[i + 1].priority = priority;

pq->count++;

printf("Inserted: %d with priority %d\n", value, priority);


Display Operation
Traverse Queue

Print Each Element

Verify Output

Displaying queue contents in priority order requires traversing all elements and ensures accurate
presentation.
PSEUDOCODE TO DISPLAY THE QUEUE
// Function to display the queue

void display(PriorityQueue *pq)

if (isEmpty(pq))

printf("Queue is Empty!\n");

return;

printf("Priority Queue Elements:\n");

for (int i = 0; i < pq->count; i++)

printf("Value: %d | Priority: %d\n", pq->items[i].data, pq->items[i].priority);

}
Dequeue Operation
1 Check if Empty
Verify queue contains elements.

PSEUDOCODE
// Function to check if the queue is empty

int isEmpty(PriorityQueue *pq)

return (pq->count == 0);

2 Store Element
Save the highest priority element.

3 Replace Top
Move the next element to the top.

Deletion ensures the queue remains correctly prioritized after removing the top element.
PSEUDOCODE FOR DEQUEUE OPERATION
// Function to delete the highest priority element (Dequeue)

void dequeue(PriorityQueue *pq)

if (isEmpty(pq))

printf("Queue is Empty! Cannot delete\n");

return;

printf("Deleted: %d with priority %d\n", pq->items[0].data, pq->items[0].priority);

// Shift elements forward

for (int i = 0; i < pq->count - 1; i++)

pq->items[i] = pq->items[i + 1];

pq->count--;

}
IMPLEMENTATION
PART 03
Implementation Strategies
Array-Based Linked List

Simple structure, but resizing can be costly. Flexible, but requires more memory.

• Easy to implement • Dynamic sizing


• Requires resizing • More memory overhead

Choosing the right strategy is crucial for optimizing performance.


C CODE TO IMPLEMENT PRIORITY QUEUE
// Priority Queue

#include <stdio.h>

#include <stdlib.h>

// Structure for a Priority Queue Node

typedef struct {

int data;

int priority;

} Node;

// Priority Queue Structure

typedef struct {

Node *items; // Dynamic array for queue

int size, count;

} PriorityQueue;

// Function to initialize the priority queue

void initialize(PriorityQueue *pq, int size)

pq->size = size;

pq->count = 0;

pq->items = (Node *)malloc(size * sizeof(Node));// Allocate memory dynamically

// Function to check if the queue is empty

int isEmpty(PriorityQueue *pq)


Time Complexity for Priority Queue
Operations:

1 Insertion (Enqueue):
Time complexity is O(1) because you can add the element at the end of the list without any comparisons.

2 Deletion (Dequeue/Extract-Min or Extract-Max):


Time complexity is O(n) because you have to scan the list to find the element with the highest (or
lowest) priority and then remove it.

3 Space Complexity:
Space complexity is O(n), as you store all the elements in the list.
APPLICATIONS
PART 04
Priority Queue Applications

Task Scheduling Network Routing


Prioritizing CPU tasks. 1 Directing network packets.
2

Event Simulation
AI Pathfinding
4 Processing events by
Finding efficient routes. 3 importance.

Priority Queues enhance efficiency and fairness in diverse computational scenarios.


ADVANTAGES AND
LIMITATIONS
PART 05
ADVANTAGES:
• Simplifies Algorithm Design:

Priority queues simplify the design of algorithms that need to repeatedly access the next most important
element, like in Dijkstra’s algorithm for finding the shortest path.

• Real-Time Processing:

Priority queues are useful in scheduling problems, as they ensure that the task with the highest priority is
always processed first, helping manage real-time constraints effectively.
LIMITATIONS:
• Insertion Order Ignored:

Unlike a regular queue, where the order of insertion is maintained, a priority queue does not maintain the
order of elements with equal priorities. This can sometimes be problematic if the order is important in
your use case.

• Memory Usage:

Depending on the implementation, priority queues can require extra memory overhead. For example, a
binary heap requires an array-based implementation, and each element must store the associated priority.
THANKS.

You might also like