Top Banner
Queues and their Applications Lecture 24 Sections 19.4 - 19.6 Robb T. Koether Hampden-Sydney College Wed, Mar 21, 2018 Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 1 / 33
77

Queues and their Applications - people.hsc.edu

Apr 07, 2022

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: Queues and their Applications - people.hsc.edu

Queues and their ApplicationsLecture 24

Sections 19.4 - 19.6

Robb T. Koether

Hampden-Sydney College

Wed, Mar 21, 2018

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 1 / 33

Page 2: Queues and their Applications - people.hsc.edu

1 Queues

2 The Queue Interface

3 Queue ApplicationsInfix Expression EvaluationBread-first Search

4 Assignment

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 2 / 33

Page 3: Queues and their Applications - people.hsc.edu

Outline

1 Queues

2 The Queue Interface

3 Queue ApplicationsInfix Expression EvaluationBread-first Search

4 Assignment

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 3 / 33

Page 4: Queues and their Applications - people.hsc.edu

Queues

DefinitionA queue is a List that operates under the principle “first in, first out”(FIFO). New elements are enqueued into the queue. Old elements aredequeued from the queue.

To enforce the FIFO principle, we enqueue and dequeue atopposite ends.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 4 / 33

Page 5: Queues and their Applications - people.hsc.edu

Implementation of Queues

Which is more accurate?A queue is a list.A queue has a list.

Use pushFront() and popBack(), orUse pushBack() and popFront().Choose a List class for which enqueuing and dequeuing will beefficient.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 5 / 33

Page 6: Queues and their Applications - people.hsc.edu

Queue Implementation

Choose an appropriate List class as a base class.Which are good choices?

ArrayListCircArrayListLinkedListLinkedListwTailDoublyLinkedListCircLinkedList

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 6 / 33

Page 7: Queues and their Applications - people.hsc.edu

Outline

1 Queues

2 The Queue Interface

3 Queue ApplicationsInfix Expression EvaluationBread-first Search

4 Assignment

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 7 / 33

Page 8: Queues and their Applications - people.hsc.edu

Queue Constructors

Queue ConstructorsQueue();Queue(const Queue& q);

Queue() constructs an empty queue.Queue(Queue&) constructs a copy of the specified queue.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 8 / 33

Page 9: Queues and their Applications - people.hsc.edu

Inspectors

InspectorsT head() const;int size() const;bool isEmpty() const;

T head() gets a copy of the element at the head of the queue.int size() gets the number of elements in the queue.bool isEmpty() determines whether the queue is empty.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 9 / 33

Page 10: Queues and their Applications - people.hsc.edu

Mutators

Mutatorsvoid enqueue(const T& value);T dequeue();void makeEmpty();

enqueue() enqueues the specified value at the tail of the queue.dequeue() dequeues and returns the element at the head of thequeue.makeEmpty() makes the queue empty.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 10 / 33

Page 11: Queues and their Applications - people.hsc.edu

Facilitators

Facilitatorsvoid input(istream& in);void output(ostream& out) const;

input() reads a queue from the specified input stream.output() writes a queue to the specified output stream.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 11 / 33

Page 12: Queues and their Applications - people.hsc.edu

Other Member Functions

Other Member Functionsvoid isValid() const;

isValid() determines whether the queue has a valid structure.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 12 / 33

Page 13: Queues and their Applications - people.hsc.edu

Non-Member Functions

Non-Member Functionsistream& operator>>(istream& in, Queue& q);ostream& operator<<(ostream& out, const Queue& q);

operator>>() reads a queue from the specified input stream.operator<<() writes a queue to the specified output stream.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 13 / 33

Page 14: Queues and their Applications - people.hsc.edu

Input and Output

Are there complications in using the List class input() andoutput() functions?Will the interpretation of head and tail be reversed between theArrayQueue and the LinkedQueue?If so, then we might need to rewrite the functions for one of thetwo Queue classes.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 14 / 33

Page 15: Queues and their Applications - people.hsc.edu

Outline

1 Queues

2 The Queue Interface

3 Queue ApplicationsInfix Expression EvaluationBread-first Search

4 Assignment

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 15 / 33

Page 16: Queues and their Applications - people.hsc.edu

Outline

1 Queues

2 The Queue Interface

3 Queue ApplicationsInfix Expression EvaluationBread-first Search

4 Assignment

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 16 / 33

Page 17: Queues and their Applications - people.hsc.edu

Infix Expression Evaluation

An infix expression with one (binary) operator is written in theorder: left-operand, operator, right-operand.Example: 3 + 4.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 17 / 33

Page 18: Queues and their Applications - people.hsc.edu

Disadvantages of Infix Notation

Parentheses are often needed to indicate order of operation.

(3 + 4) ∗ (5 + 6).

Operators at different precedence levels follow a precedencehierarchy.

3 + 4 ∗ 5 − 6/7.

Operators at the same precedence level have a left or rightassociativity.

100 − 50 − 10 − 5 − 1.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 18 / 33

Page 19: Queues and their Applications - people.hsc.edu

Infix Expression Evaluation

Infix to Postfix AlgorithmTo evaluate an infix expression, we first convert it to postfix.Begin with an empty stack and an empty queue.Process the tokens from left to right according to the followingrules.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 19 / 33

Page 20: Queues and their Applications - people.hsc.edu

Infix Expression Evaluation

Infix to Postfix AlgorithmIf the token is a number, enqueue the token.If the token is a left parenthesis, push the token onto the stack.If the token is a right parenthesis,

Pop tokens off the stack and enqueue them until a left parenthesisis popped.Discard the right and left parentheses.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 20 / 33

Page 21: Queues and their Applications - people.hsc.edu

Infix Expression Evaluation

Infix to Postfix AlgorithmIf the token is an operator,

Pop tokens off the stack and enqueue them untilAn operator of lower precedence is on top of the stack, orA left parenthesis is on top of the stack, orThe stack is empty.

Push the operator onto the stack.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 21 / 33

Page 22: Queues and their Applications - people.hsc.edu

Infix Expression Evaluation

Infix to Postfix AlgorithmAfter processing the last token, pop all tokens off the stack andenqueue them.The queue now contains the expression in post-fix notation.Now process the queue as a post-fix expression.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 22 / 33

Page 23: Queues and their Applications - people.hsc.edu

Example

Use the algorithm to convert the expression

(7 + 5)/(9 − 3 ∗ 2) ∗ 6

to postfix.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 23 / 33

Page 24: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue

( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 25: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (

7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 26: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7

+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 27: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 7

5 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 28: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5

) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 29: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +

/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 30: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +

( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 31: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +

9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 32: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9

− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 33: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 9

3 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 34: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3

∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 35: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 3

2 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 36: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2

) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 37: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −

∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 38: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /

6 ∗ 7 5 + 9 3 2 ∗ − / 6(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 39: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 40: Queues and their Applications - people.hsc.edu

Example

Token Stack Queue( (7 ( 7+ ( + 75 ( + 7 5) 7 5 +/ / 7 5 +( / ( 7 5 +9 / ( 7 5 + 9− / ( − 7 5 + 93 / ( − 7 5 + 9 3∗ / ( − ∗ 7 5 + 9 32 / ( − ∗ 7 5 + 9 3 2) / 7 5 + 9 3 2 ∗ −∗ ∗ 7 5 + 9 3 2 ∗ − /6 ∗ 7 5 + 9 3 2 ∗ − / 6

(end) 7 5 + 9 3 2 ∗ − / 6 ∗

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 24 / 33

Page 41: Queues and their Applications - people.hsc.edu

Outline

1 Queues

2 The Queue Interface

3 Queue ApplicationsInfix Expression EvaluationBread-first Search

4 Assignment

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 25 / 33

Page 42: Queues and their Applications - people.hsc.edu

Tree Structures

A tree is a structure that has the following properties.It has a root node.Every node may have any finite number of children nodes.Every node except the root node has exactly one parent node.There any “loops” in the tree.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 26 / 33

Page 43: Queues and their Applications - people.hsc.edu

Searching Trees

Suppose that we have a tree structure that stores a value at eachnode.We would like to search the tree for a specific value.There are two general strategies:

Depth-first searchBreadth-first search

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 27 / 33

Page 44: Queues and their Applications - people.hsc.edu

Depth-first Search

DefinitionA depth-first search will follow a single path from parent to child until itreaches a dead-end. At that point, it backs up and follows a differentpath, and so on, until either it finds what it is looking for or it runs out ofnodes to search.

We would use a stack to implement a depth-first search.We push each node we visit onto the stack.When we hit a dead-end, we pop nodes from the stack until we canfollow a different path.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 28 / 33

Page 45: Queues and their Applications - people.hsc.edu

Breadth-first Search

DefinitionA breadth-first search will visit all of the child nodes of the root nodebefore it visits any of their children. It repeats this strategy level by leveldown the tree.

We would use a queue to implement a breadth-first search.Begin with the root node.When a node is visited, enqueue all of its children.Dequeue a node from the queue and visit that node next.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 29 / 33

Page 46: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue:

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 47: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: B, C

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 48: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: C, D

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 49: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: D, E, F

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 50: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: E, F, G, H

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 51: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: F, G, H, I, J

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 52: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: G, H, I, J, K

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 53: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: H, I, J, K, L

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 54: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: I, J, K, L

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 55: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: J, K, L

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 56: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: K, L, M, N

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 57: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: L, M, N

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 58: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: M, N

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 59: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue: N

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 60: Queues and their Applications - people.hsc.edu

Breadth-first Search

A

B C

D E F

G H I J

L M

K

N

Queue:

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 30 / 33

Page 61: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current Queue

A B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 62: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B C

B C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 63: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C D

C D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 64: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E F

D E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 65: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G H

E F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 66: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I J

F G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 67: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J K

G H I J K LH I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 68: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K L

H I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 69: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K L

I J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 70: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K L

J K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 71: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M N

K L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 72: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M N

L M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 73: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M N

M NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 74: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M NM N

N

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 75: Queues and their Applications - people.hsc.edu

Breadth-first Search

Current QueueA B CB C DC D E FD E F G HE F G H I JF G H I J KG H I J K LH I J K LI J K LJ K L M NK L M NL M NM NN

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 31 / 33

Page 76: Queues and their Applications - people.hsc.edu

Outline

1 Queues

2 The Queue Interface

3 Queue ApplicationsInfix Expression EvaluationBread-first Search

4 Assignment

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 32 / 33

Page 77: Queues and their Applications - people.hsc.edu

Assignment

AssignmentRead Sections 19.4 - 19.6.

Robb T. Koether (Hampden-Sydney College) Queues and their Applications Wed, Mar 21, 2018 33 / 33