360 likes | 2.49k Views
This presentation on Queue In Data Structure will acquaint you with all the basics of Queue data structure from scratch. In this introduction to queue with example video we will provide you with algorithms of queue operations to make you understand the flow of data. You will also understand the importance of queue data structure through its various applications. So, let's begin!<br><br>The topics covered in this video on Queue in Data Structure are:<br>1. Introduction<br>2. Structure of Queue<br>3. Queue Operation<br>4. Types of Queues and their structures<br>5. Application of Queues<br>
E N D
What’s in It for You? Introduction to Queue Data Structure Structure of Queue Queue Operations Types of Queues and Their Structures Applications of Queues
At present people rely on messaging applications like WhatsApp, Facebook messenger, and Instagram chats to communicate with friends and family. Introduction to Queue Data Structure
In these messaging applications, the order of messages is maintained for each user. Introduction to Queue Data Structure
How are these applications maintaining the order of text messages? Queues are maintained for each user containing messages to be delivered… Once user connects to network messages in the queue gets delivered!
Let’s take an example of a movie ticket counter to understand the structure of queue... Structure of Queue Both the ends are fixed! Open at both ends
Let’s take an example of a movie ticket counter to understand the structure of queue... Structure of Queue Person who enters first receives the movie ticket first Person who enters last will receive the ticket last
The queue is a linear collection of different data types. Both the ends of queue data structure are open allowing it to have different operations at different ends. Structure of Queue FRONT (Deletion) REAR (Insertion) Both the ends remain open Linear collection of different data types The end at which insertion takes place is called REAR. The end at which deletion takes place is known as FRONT.
Structure of queue depends on perspective of programmer. For instance, If left end = FRONT Then right end = FRONT If left end = REAR Then right end = REAR Structure of Queue
QueueOperations 1 Enqueue() : This operation is used to store the elements in the Queue Dequeue() : This operation is used to remove elements from Queue 2 isFull() : Checks if the Queue is full or not isNull() : Evaluates if the queue is empty 3 4 Peek() : get the element from the front of the Queue without removing it
We will gauge insight of queue operations by performing them on queue one by one: Queue Operations Enqueue(Argument) IsFull() Dequeue() peek() isNull()
Initially, let’s assign some random size to queue. Queue Operations For example, int queue[3]; -1 FRONT REAR
ALGORITHM- Check if the queue is full. If the queue is full, produce overflow error and exit. If the queue is not full, increment REAR pointer to point the next empty space. Add DATA element to the queue location, where the REAR is pointing. Element is added successfully. Enqueue(Arg..) 1. Enqueue(5) Our queue is empty! 5 -1 + 1 = 0 0 FRONT REAR
2. Enqueue(1) 1 5 Enqueue(Arg..) 0 1 REAR = REAR + 1 REAR = 0 + 1 = 1 REAR FRONT 3. Enqueue(-2) 5 1 -2 1 0 2 REAR REAR= 1 + 1 = 2 FRONT
ALGORITHM- Begin procedure isFull(). If REAR equals to MAXSIZE. Return “Queue is full” Else, Return “Queue is not full”. 4. isFull( ) 5 1 -2 3 integer variables = 12 Bytes! REAR So, let’s say size of our array is 12 bytes. 0 1 2 Thus, output will be “Queue is Full”
ALGORITHM- Check if the queue is empty. If the queue is empty, produce underflow error and exit. If the queue is not empty, access the data where FRONT is pointing. Increment front pointer to point to the next available data. Element is removed successfully. 5. Dequeue( ) Dequeue() This queue is not empty! 5 1 -2 0 1 2 FRONT FRONT REAR
ALGORITHM- Begin procedure Peek(). Check if the queue is empty and return “Queue is Empty”. If the queue is not empty, access DATA from FRONT node. End of procedure Peek. 6. Peek( ) This queue is not empty. -2 1 1 2 Data will be accessed with temporary variable! FRONT REAR
7. Dequeue() -2 1 Dequeue( ) 2 1 FRONT REAR FRONT = 1 + 1 = 2 8. Dequeue() -2 2 FRONT and REAR both will point to null now FRONT REAR
ALGORITHM- Begin procedure isEmpty(). If FRONT is equal to NULL (-1 as per our convention). Return “Queue is Empty”. End of procedure Peek. 9. isEmpty( ) -1 OUTPUT : Queue is Empty FRONT
Linear queue 1. 1. The queue structure we have discussed till the time is known as linear or simple queue. 2. 2. 3. 3. FRONT REAR 4. 4.
Circular queue 1. 1. Last node of this queue is connected to the first node making circular link. That is why it is also called as Ring Buffer. Circular queue is better version of linear queue. 2. 2. 3. 3. Circular link 5 1 -2 4. 4. First Node Last Node
Priority queue 1. 1. A priority queue is another special type of Queue data structure in which each element has some priority assigned with it. 2. 2. In priority queue, insertion occurs based on the arrival and deletion occurs according to the priority. 3. 3. REAR Node FRONT Node 4. 4. Least element Largest element ENQUEUE DEQUEUE In this queue priority of elements is dependent on their order.
Double ended queue 1. 1. Deque is a linear data structure in which the insertion and deletion operations are performed from both ends. Deque can be used as stack as well as Queue as it allows the insertion and deletion operations on both ends. 2. 2. REAR 3. 3. FRONT REAR 4. 4. If insertion happens at one end and deletion at another then that deque will be considered as queue. If both insertion and deletion happens at one end then that deque will be considered as stack.
Queues in Operating Systems Applications of Queues While using multiple applications, Dead-lock occurs in the system leading to response delay. At that instance, OS utilize queues to maintain multiple processes until their execution.
Queues in printers Applications of Queues Queue data structure is used in printers to maintain the order of pages while printing. One after another pages will be removed from queue and will be printed by printer. Pages we want to print in Order, will be stored in the queue.
Queues in software applications Applications of queue Applications like Domino’s, Swiggy and Zomato uses a queue for maintaining food order status. Once your order-ID reaches front of the queue, then Delivery will be processed! When you place an order from online portal, your Order-ID enters the queue
Final Key Take-Aways The operations that allows manipulation Of data are Enqueue and dequeue. Used to serve purpose of FCFS There are four types of queues. Can handle multiple data-types Queue is a linear data structure.