QUEUE in data-structure (classification, working procedure, Applications)

MehediHSourov 107 views 16 slides Apr 26, 2024
Slide 1
Slide 1 of 16
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16

About This Presentation

About Queue Data structure


Slide Content

QUEUE IN DATA STRUCTURE PRESENTED BY- MEHEDI HASAN BATCH-D-74

INDEX Introduction Different types of Queue Applications Conclusion Algorithms Working procedure Calculating Complexity Advantage & Disadvantage

INDTODUCTION Queue is linear data structure. It is a way of storing and organizing data. It follows the principle of “first in first out”

Queue Different types of Queue

Operations Enqueue (): used to inert elements to the end of the Queue Dequeue (): Remove elements from the frontal side Isempty () : To check the Queue is empty or not Peek() : Returns the element of the first at the queue

Linear Queue Algorithms Dequeue (): Check if the queue is empty (front == rear == -1). If empty, display an underflow error. Otherwise, increment front by 1. Remove the element from the front position in the array. Complexity: The time complexity of insertion, deletion and peek operation is O(1). If resizing is necessary (i.e., when the array is full), then the enqueue operation may take O(n) time in the worst case, where n is the current size of the queue. In Linear Queue, an insertion takes place from one end while the deletion occurs from another end. Algorithms of Linear Queue: Set array – arr [ i ] Set front and rear to -1 to signify an empty queue. Enqueue (): Check if queue is full (rear == SIZE - 1). If full, display an overflow error. Otherwise, increment tail/rear by 1. Insert the element at rear position in the array.

Linear Queue Working procedure

Linear Queue Advantage and Disadvantage SL No. Advantage Disadvantage 1 Simple Implementation Fixed Capacity in Array-based Implementation 2 Efficient for FIFO Operations Memory Fragmentation in Array-based Implementation 3 Constant Time Complexity for Basic Operations Inefficient Removal of Arbitrary Elements/ Limitation of implementation 4 Suitable for Applications with Limited Memory Not Suitable for Priority-based Operations

Priority Queue Algorithms Dequeue (): Remove the element with the highest priority. Rearrange the array to fill the gap left by the removed element. Complexity: The time complexity of insertion, deletion is O(log n). In Priority Queue elements are arranges based on their priority (values). Priority queues can be implemented using Linked List, Heap, Binary search tree and Array based. Algorithms of Array-based priority Queue: Set array – arr [ i ] Set front and rear to -1 to signify an empty queue. Enqueue (): Add the element at the end of the array. If necessary, reorder the array to maintain the priority order. This can be achieved by comparing the priority of the newly added element with its parent and swapping if necessary until the priority order is restored.

Priority Queue working procedure Dequeue () Enqueue () 7 6

D Queue Algorithms Algorithm Pop_Back ( deque ): 1. If deque is empty, return an error. 2. Get the element from the tail node of the deque . 3. If deque has only one node: - Set both head and tail pointers to null. 4. Else: - Set the previous node of the current tail as the new tail. - Set the next pointer of the new tail to null. 5. Decrement the size of the deque . 6. Return the element. assume a deque implemented using a doubly linked list Algorithms of D-Queue: Algorithm Push_Front ( deque , element): 1. Create a new node with the given element. 2. If deque is empty: - Set the new node as both the head and tail of the deque . 3. Else: - Set the previous pointer of the current head node to point to the new node. - Set the next pointer of the new node to point to the current head node. - Update the head of the deque to point to the new node. 4. Increment the size of the deque .

D Queue Algorithms Algorithm Pop_Front ( deque ): 1. If deque is empty, return an error. 2. Get the element from the head node of the deque . 3. If deque has only one node: - Set both head and tail pointers to null. 4. Else: - Set the next node of the current head as the new head. - Set the previous pointer of the new head to null. 5. Decrement the size of the deque . 6. Return the element. assume a deque implemented using a doubly linked list Algorithms of D-Queue: Algorithm Push_Back ( deque , element): 1. Create a new node with the given element. 2. If deque is empty: - Set the new node as both the head and tail of the deque . 3. Else: - Set the next pointer of the current tail node to point to the new node. - Set the previous pointer of the new node to point to the current tail node. - Update the tail of the deque to point to the new node. 4. Increment the size of the deque .

D Queue Working procedure

Queue Applications of Queue Operating Systems: Task scheduling: Queues are used in operating systems to manage tasks and processes. Print spooling: Print jobs are placed in a queue and processed in the order they are received. Networking: Network packet handling: Queues are used in network routers and switches to manage incoming and outgoing packets. Data Structures: Breadth-first search (BFS): Queues are used in graph traversal algorithms like BFS to explore nodes level by level. Cache replacement policies: Queues are used in cache implementations to implement replacement policies like FIFO (First-In-First-Out). Web Servers: Request handling: Queues are used in web servers to manage incoming HTTP requests. Hardware Design: CPU scheduling: Queues are used in computer architecture and CPU scheduling algorithms to manage the execution of processes on a multi-core processor.

Queue Conclusion There can be a lot of memory wastage in static queues, as no matter what is the size of the queue, the space occupied by it remains the same. Traversing a queue will delete the foremost element on each iteration, eventually, emptying the queue.