data structures and algorithms queue - wordpress.com · 4 queue •queue: a collection whose...
TRANSCRIPT
IT 4043
Data Structures and Algorithms
Budditha Hettige
Department of Computer Science
1
Queue
5
Course Outline• Introduction to DSA
• Abstract Data Types (ADT)
• List operation using arrays
• Stacks
•Queues• Recursion
• Link List
• Sorting
• Searching
• Algorithms Analysis
2
3
Objectives
• Examine queue processing
• Define a queue abstract data type
• Demonstrate how a queue can be used
to solve problems
4
4
Queue• Queue: a collection whose elements are
added at one end (the rear or tail of the queue) and removed from the other end (the front or head of the queue)
• A queue is a FIFO (first in, first out) data structure
• Any waiting line is a queue:
–The check-out line at a grocery store
–The cars at a stop light
–An assembly line
Conceptual View of a Queue
Front of queue
Rear of queue
5
Conceptual View of a Queue
Front of queue
Adding an element
The new element is added to the rear of the queue
5
Removing an element
New front element of queue
The element is removed from the front of the queue
Conceptual View of a Queue
6
9
Uses of Queues in Computing
• Printer queue
• Keyboard input buffer
• GUI event queue (click on buttons, menu items)
• To encode messages
• For any kind of problem involving FIFO data
10
Operations on a Queue
Operation Description
remove Removes an element from the front of the queue
insert Adds an element to the rear of the queue
isFull Determines whether the queue is full
isEmpty Determines whether the queue is empty
Implementation of a Queue
11
12
An Array Implementation of a Queue
13
An Array Implementation of a Queue
Before After
14
An Array Implementation of a Queue
15
An Array Implementation of a Queue
Summary• Queue: a collection whose elements are
added at one end and removed from the
other end
• A queue is a FIFO (first in, first out) data
structure
• Queue Implementation (Java)
16
Questions
1. Specify 3 usages of Queues in Computing.
2. Identify which of the following is/are true? In
each case justify your answer.
a. Web browsers use queues to retrieve data
b. In the front fix array bases queue
implementation, remove operation is less
efficient than insert
17
Thank you!
18