0% found this document useful (0 votes)
27 views4 pages

CSE 2151 Lecture 5

1. The document discusses queues as a first-in, first-out data structure and two common implementations using arrays and linked lists. Elements are added to the back of the queue and removed from the front. 2. Methods for queue operations are described including enqueue, dequeue, first, size, and isEmpty. Problems with typical array-based queues and solutions using circular arrays are covered. 3. Applications of queues include printer queues, playing audio/video files, and computer processing tasks in order of arrival.

Uploaded by

saymyname.pt
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)
27 views4 pages

CSE 2151 Lecture 5

1. The document discusses queues as a first-in, first-out data structure and two common implementations using arrays and linked lists. Elements are added to the back of the queue and removed from the front. 2. Methods for queue operations are described including enqueue, dequeue, first, size, and isEmpty. Problems with typical array-based queues and solutions using circular arrays are covered. 3. Applications of queues include printer queues, playing audio/video files, and computer processing tasks in order of arrival.

Uploaded by

saymyname.pt
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
You are on page 1/ 4

Queue

Course No.: 0714 09 CSE 2151, Course Title: Data Structures and Algorithms
Electronics and Communication Engineering Discipline, Khulna University, Khulna
Md. Farhan Sadique
Email: [email protected]
This lecture is not a study material. Use this lecture as an outline. Follow the outline to study from the mentioned sources
after each section header. The sections of this lecture have been prepared from the mentioned sources.

1. Queue (Goodrich et al.: 6.2)


Queue is a collection of objects that are inserted and removed according to the first-in, first-out (FIFO)
principle. We usually say that elements enter a queue at the back and are removed from the front.

2. Implementing Queue (Goodrich et al.: 6.2.1)

• enqueue(e): Adds element e to the back of queue.


• dequeue( ): Removes and returns the first element from the queue (or null if the queue is empty).
• first( ): Returns the first element of the queue, without removing it (or null if the queue is empty).
• size( ): Returns the number of elements in the queue.
• isEmpty( ): Returns a boolean indicating whether the queue is empty.
Data Structures and Algorithms – Lecture 4 Md. Farhan Sadique

2.1. Array-Based Queue Implementation (Goodrich et al.: 6.2.2)

What are the problems in typical array-based queue?

Using an Array Circularly:


In developing a robust queue implementation, we allow both the front and back of the queue to drift rightward,
with the contents of the queue “wrapping around” the end of an array, as necessary.

2
Data Structures and Algorithms – Lecture 4 Md. Farhan Sadique

Fig. Array-based implementation of a queue.

3
Data Structures and Algorithms – Lecture 4 Md. Farhan Sadique
2.2. Implementing a Queue with a Singly Linked List (Goodrich et al.: 6.2.3)

Fig. Implementation of a Queue using a SinglyLinkedList.


What are some applications of Queue? (https://www.geeksforgeeks.org/applications-of-queue-data-structure/)
Review Question
1. What values are returned during the following sequence of queue operations, if executed on an initially
empty queue? enqueue(5), enqueue(3), dequeue(), enqueue(2), enqueue(8), dequeue(), dequeue(),
enqueue(9), enqueue(1), dequeue(), enqueue(7), enqueue(6), dequeue(), dequeue(), enqueue(4),
dequeue(), dequeue().

Bibliography
• Book: Data Structures and Algorithms in Java, Sixth Edition - Michael T. Goodrich, Roberto Tamassia and
Michael H. Goldwasser
• Website: https://www.geeksforgeeks.org/applications-of-queue-data-structure/

You might also like