0% found this document useful (0 votes)
43 views8 pages

Understanding Queue Data Structures

Understanding Queue in good way

Uploaded by

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

Understanding Queue Data Structures

Understanding Queue in good way

Uploaded by

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

TECHNO MAIN SALTLAKE

QUEUE ADT

• NAME: SAPTARSHI SARKAR


• DEPARTMENT: ELECTRONICS AND COMMUNICATION ENGINEERING (ECE-B)
• SUBJECT NAME: DATA STRUCTURE & ALGORITHMS
• SUBJECT CODE: ES-CS 301
• ROLL NO: 13000323085
• REGISTRATION NUMBER: 231300110690(2023-24)
CONTENTS
 INTRODUCTION

 BASIC OPERATIONS IN QUEUE

 TYPES OF QUEUE

 APPLICATIONS
INTRODUCTION
 Queue is a linear data structure that follows a particular order in which the operations
are performed for storing data.
 The order is First In First Out (FIFO). One can imagine a queue as a line of people
waiting to receive something in sequential order which starts from the beginning of the
line.
 It is an ordered list in which insertions are done at one end which is known as the rear
and deletions are done from the other end known as the front.
 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.
BASIC OPERATIONS IN QUEUE
1.#define MAX_SIZE 100
[Link] queue[MAX_SIZE]; ❑ enqueue(): Inserts an element at the end of the
[Link] front = -1; queue i.e. at the rear end.
[Link] rear = -1;
5. void enqueue(int element) { ❑ dequeue(): This operation removes and returns an
6. if (rear == MAX_SIZE - 1) { element that is at the front end of the queue.
7. printf(“OVERFLOW");
8. } ❑ front(): This operation returns the element at the
9. if (front == -1 && rear==-1) { front end without removing it.
10. front++;
11. rear++; ❑ rear(): This operation returns the element at the
12. queue[rear] = element; rear end without removing it.
13.}
14. ❑ isEmpty(): This operation indicates whether the
[Link] dequeue() { queue is empty or not.
16. if (front == -1 || front > rear) {
17. printf("Queue is empty"); ❑ isFull(): This operation indicates whether the
18. } queue is full or not.
19. int element = queue[front];
20. front++; ❑ size(): This operation returns the size of the queue
21. return element; i.e. the total number of elements it contain.
22.}
TYPES OF QUEUE
1) Simple Queue: Simple queue also known as a linear queue is the most basic version of a
queue. Here, insertion of an element or Enqueue takes place at the rear end and removal of
an element or Dequeue takes place at the front end. Here problem is that if we pop some
item from front and then rear reach to the capacity of the queue and although there are
empty spaces in front means the queue is not full but as per condition in isFull() function, it
will show the queue is full.
2) Circular Queue: In a circular queue, the element of the queue act as a circular ring. The
working of a circular queue is similar to the linear queue except for the fact that the last
element is connected to the first element. Its advantage is that the memory is utilized in a
better way. This is because if there is an empty space then an element can be easily added at
that position using modulo capacity(%n).
3) Priority Queue: This queue is a special type of queue. Its specialty is that it arranges the
elements in a queue based on some priority. The priority can be something where the
element with the highest value has the priority so it creates a queue with decreasing order of
values.
4) Dequeue: Dequeue is also known as Double Ended Queue. As the name suggests double
ended, it means that an element can be inserted or removed from both ends of the queue,
unlike the other queues in which it can be done only from one end. Because of this property,
it may not obey the First In First Out property.
APPLICATIONS
Queue is used when things don’t have to be processed immediately, but have to be processed
in First In First Out order like Breadth First Search. This property of Queue makes it also useful in
following kind of scenarios.
❖ When a resource is shared among multiple consumers. Examples include CPU scheduling, Disk
Scheduling.
❖ When data is transferred asynchronously (data not necessarily received at same rate as sent)
between two processes. Examples include IO Buffers, pipes, file IO, etc.
❖ Multi programming: Multi programming means when multiple programs are running in the main
memory. It is essential to organize these multiple programs and these multiple programs are
organized as queues.
❖ Network: In a network, a queue is used in devices such as a router or a switch. another application of a
queue is a mail queue which is a directory that stores data and controls files for mail messages.
❖ Job Scheduling: The computer has a task to execute a particular number of jobs that are scheduled to
be executed one after another. These jobs are assigned to the processor one by one which is organized
using a queue.
❖ Shared resources: Queues are used as waiting lists for a single shared resource.
REFERENCES
❑ [Link]

❑ [Link]

❑ [Link]

❑ ResearchGate
THANK
YOU

Common questions

Powered by AI

A significant drawback of a simple queue is that it can show as full even if there are empty spaces at the front, due to the movement of the rear pointer as elements are dequeued. A circular queue addresses this by connecting the last element back to the first, allowing for more efficient use of space as you can add elements to empty spaces at the front using modulo operations .

A priority queue is more suitable in situations where the elements need to be processed based on a priority rather than the order of arrival. This is useful in tasks like job scheduling where certain tasks need immediate attention over others, or in network traffic management where packets with higher priority should be transmitted first .

A dequeue, or double-ended queue, allows insertion and removal of elements from both ends, unlike typical queues which restrict operations to one end for insertion (rear) and the opposite end for removal (front). This flexibility makes it incomparable to other queue types, as it can deviate from the FIFO order traditionally associated with queue operations .

The main operations in a queue include: enqueue(), which inserts an element at the rear end; dequeue(), which removes an element from the front; front(), which returns the front element without removing it; rear(), which returns the rear element without removing it; isEmpty(), to check if the queue is empty; isFull(), to check if the queue is full; and size(), which returns the number of elements in the queue .

Multi-programming environments use queues to organize and run multiple programs in memory concurrently. Each program waiting for execution is placed in a queue, allowing for efficient resource allocation and systematic scheduling of CPU time. This reduces CPU idle time and enhances process efficiency by systematically managing workloads, ultimately increasing overall system performance without the need for manual intervention .

Using queues in job scheduling ensures that tasks are executed in a systematic and organized manner (FIFO), allowing for predictable execution order and fairness among jobs. If queues weren't used, managing jobs would become chaotic, leading to resource contention, inefficiencies, and delays as tasks could be processed arbitrarily or inequitably, reducing system performance and throughput .

Queues facilitate asynchronous data transfer by managing data arriving at different rates from when it's processed. By placing incoming data into a queue, processes can handle each piece of data sequentially without being overwhelmed by fluctuating rates of data input. This approach prevents data loss, ensures consistent processing rates, and accommodates varying processing speeds between sender and receiver, which is critical in real-time data environments like I/O buffers and network communications .

In computer networking, queues manage data packets in routers and switches to ensure an orderly transmission and avoid congestion. For system resources, queues manage processes in CPU scheduling, providing a systematic allocation of CPU time. They are useful because they handle multiple demands fairly and efficiently, ensuring resources are distributed according to specific rules (e.g., FIFO), essential for maintaining system throughput and fairness .

In data structures, a queue follows the FIFO principle where the first element added is the first one to be removed, mimicking a real-world queue scenario, such as people standing in line. In contrast, a stack follows the LIFO (Last In First Out) principle, where the last element added is the first one to be removed, similar to a stack of plates where you take the topmost plate first .

A queue is effective for Breadth First Search algorithms because it processes nodes in the order they are discovered (FIFO), ensuring that all nodes at the current depth are traversed before moving to the next depth level. This orderly processing is crucial for correctly exploring all vertices at a given distance from the source in graph-related algorithms .

You might also like