Data Structure - 7 Queue

AndiNurkholis1 23 views 16 slides Sep 17, 2025
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

The Queue slide the Data Structures course include:
1. Definition of queue
2. Characteristic of queue
3. Basic operation of queue
4. Enqueue operation
5. Dequeue operation
6. Peek operation
7. Isempty operation
9. Size operation
10. Application of queue
11. Advantage of queue
12. Disadvantage of que...


Slide Content

Department of Informatics
Faculty of Industrial Engineering
Universitas Pembangunan Nasional “Veteran” Yogyakarta
Data
Structure
Andi Nurkholis, S.Kom., M.Kom.
Queue: Concept
& Implementation
September 29, 2025

Definition of Queue
Queue is a linear data structure that stores elements sequentially according to
specific rules. Insertion occurs at the back, while deletion occurs at the front.
Queues apply the FIFO (First In, First Out) principle, so the first element
inserted is the first to be removed. A simple analogy is a queue at a ticket
counter, where people who arrive early are served before those who arrive later.
Queues have two main operations:
üEnqueue: Adds an element to the end of the queue.
üDequeue: Removes an element from the beginning of the queue.

Characteristic ofQueue
1.FIFO (First In, First Out)
2.Limited Access
3.Dynamic Length

Characteristic of Queue
1.FIFO (First In, First Out): The main principle of a queue is that the first
element entered will be the first to exit. For example, a queue at a ticket
counter, where people who arrive first are served first. In programming,
incoming data must wait its turn until all previous data has been processed,
making it suitable for systems that require fair processing order.

Characteristic of Queue
2.Limited Access: Queues only allow two operations: enqueue to add elements
from the back and dequeue to remove elements from the front. Unlike arrays
or linked lists, this limitation maintains efficiency and order.
3.Dynamic Length: Queues can be created with arrays (fixed capacity) or linked
lists (flexible capacity). Arrays have limited size, while linked lists adjust as
needed as memory allows.

Basic Operation ofQueue
1.Enqueue
2.Dequeue
3.Peek
4.IsEmpty
5.Size

Enqueue Operation
1.Check the queue status to ensure it's not full or that there's still available
memory.
2.Move rear to the next position or create a new node.
3.Store the new data at position rear.
4.Update rear to point to the last element.
5.Confirm the entry; the queue now grows according to the FIFO principle.

Dequeue Operation
1.Check the queue's condition to ensure it's not empty (underflow).
2.Take the data from the front position as the element to be deleted.
3.Shift the front to the next position (in an array) or move the pointer to the
next node (in a linked list).
4.Remove the old element from memory (in a linked list).
5.Confirm the element is removed; the queue is now reduced according to the
FIFO principle.

Peek Operation
1.Check the queue's condition first to ensure it's not empty.
2.If the queue uses an array, directly access the element at the front position
without changing the values of the front or rear variables.
3.If the queue uses a linked list, access the data at the node pointed to by
the head without moving the head pointer.
4.Return the value of that element as the peek result.

IsEmpty Operation
1.Start checking the queue's condition using a pointer variable.
2.In an array queue, check whether front > rear or whether the queue has
never been filled.
3.In a linked list queue, check whether head = NULL.
4.If the condition indicates no elements, return true (the queue is empty).
5.If not, return false (the queue still contains data).

Size Operation
1.Initialize the size variable to store the number of elements.
2.Check the queue's condition; if it's empty, return 0.
3.In the queue array, calculate the number of elements using the formula
(rear - front + 1).
4.In the linked list queue, traversal from the head to the last node increments
the counter.
5.Return the size value as the total number of elements in the queue.

Application of Queue
1.Process Management in Operating Systems: Queues are used to manage
process execution, for example in Round Robin Scheduling, where processes
alternately wait for their turn at the CPU. Queues are also used in task
scheduling, print queues, and I/O request queues.
2.Data Processing in Computer Networks: Data is broken down into packets
that are stored in queue-based buffers. Routers, switches, and servers utilize
queues to manage packets to maintain orderly data flow and prevent packet
loss.
3.Service Queue Systems: Queues model real-world queues, such as those at
banks, hospitals, or ticket counters. In simulations, queues represent
customer arrivals, service, and order.

Application of Queue
4.Graph Search Algorithms: In Breadth-First Search (BFS), a queue is used to
traverse the graph incrementally. The initial vertex is processed, then its
neighbors are added to the queue. This ensures a systematic search from
level to level.
5.Data Buffering in Multimedia and Streaming: Streaming applications store
audio or video chunks in a queue before playing them. This mechanism
maintains smooth playback while reducing latency.
6.System Simulation and Modeling: Queues are used in Discrete Event
Simulation (DES) to model real-world queues, such as call centers, production
lines, or logistics distribution.

Advantage of Queue
1.Simple and Easy to Implement: Queues follow the FIFO principle, similar to
a queue at a counter, making them easy for students to understand and
practice in programming.
2.Flexible Access: Enqueue operations are only performed at the back and
dequeue operations are only performed at the front, ensuring fair and
orderly data management.
3.Efficient Memory Usage: Implementation with linked lists allows for dynamic
queue size, adjusting data without wasting memory like static arrays.
4.Many Real Applications: Queues are used in operating systems, computer
networks, multitasking programming, making them essential to learn.

Disadvantage of Queue
1.Size Limitations: In static arrays, the queue capacity is predetermined. If it's
too small, overflow occurs; if it's too large, memory space is wasted.
2.Overflow and Underflow: Overflow occurs when adding elements to a full
queue, while underflow occurs when removing elements from an empty
queue. Both are prevented by condition checks.
3.Limited Access: Queues only allow operations at the front and back of the
queue; they don't support random access like arrays or linked lists.
4.Complex Memory Management: Dynamic implementations with pointers are
more flexible, but risk memory leaks if not careful.

Department of Informatics
Faculty of Industrial Engineering
Universitas Pembangunan Nasional “Veteran” Yogyakarta
Andi Nurkholis, S.Kom., M.Kom.
September 29, 2025
Done
Thank
You