Top Banner
IT 4043 Data Structures and Algorithms Budditha Hettige Department of Computer Science 1 Queue 5
18

Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

Jul 09, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

IT 4043

Data Structures and Algorithms

Budditha Hettige

Department of Computer Science

1

Queue

5

Page 2: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

Course Outline• Introduction to DSA

• Abstract Data Types (ADT)

• List operation using arrays

• Stacks

•Queues• Recursion

• Link List

• Sorting

• Searching

• Algorithms Analysis

2

Page 3: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

3

Objectives

• Examine queue processing

• Define a queue abstract data type

• Demonstrate how a queue can be used

to solve problems

Page 4: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

4

Page 5: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

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

Page 6: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

Conceptual View of a Queue

Front of queue

Rear of queue

5

Page 7: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

Conceptual View of a Queue

Front of queue

Adding an element

The new element is added to the rear of the queue

5

Page 8: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

Removing an element

New front element of queue

The element is removed from the front of the queue

Conceptual View of a Queue

6

Page 9: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

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

Page 10: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

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

Page 11: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

Implementation of a Queue

11

Page 12: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

12

An Array Implementation of a Queue

Page 13: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

13

An Array Implementation of a Queue

Before After

Page 14: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

14

An Array Implementation of a Queue

Page 15: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

15

An Array Implementation of a Queue

Page 16: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

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

Page 17: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

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

Page 18: Data Structures and Algorithms Queue - WordPress.com · 4 Queue •Queue: a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other

Thank you!

18