Queues and Priority Queues

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Fundamentals of Python: From First Programs Through Data Structures
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 4.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Queues and Priority Queues
CS Data Structures I Chapter 7 Queues II. 2 Topics Queue Application Simulation Comparison of List, Stack and Queue.
COSC2006 Chapter 8 Queues III
Chapter 13 Queues and Priority Queues CS Data Structures Mehmet H Gunes Modified from authors’ slides.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Queues. From last time: Java's built-in java.util.Stack class Consider the javadoc for Java’s built-in java.util.Stack class (
Sorted Lists and Their Implementations Chapter 12 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Queues, Deques and Priority Queues Chapter 10 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Queues, Deques, and Priority Queues Chapter 23 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Data Abstraction: The Walls
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
Implementations of the ADT Stack Chapter 7 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 6 Stacks CS Data Structures Mehmet H Gunes Modified from authors’ slides.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
Stacks and Queues Introduction to Computing Science and Programming I.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Queues, Deques, and Priority Queues Chapter 23 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Tree Implementations Chapter 16 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
Data Structures: A Pseudocode Approach with C1 Chapter 4 Objectives Upon completion you will be able to: Explain the design, use, and operation of a queue.
EC-211 DATA STRUCTURES LECTURE 9. Queue Data Structure An ordered group of homogeneous items or elements. Queues have two ends: – Elements are added at.
The Abstract Data Type Queue A queue New items enter at the back, or rear, of the queue Items leave from the front of the queue First-in, first-out (FIFO)
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Chapter 8 Queues. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
Heaps Chapter 17 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 7 Queues Introduction Queue applications Implementations.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 7 A Queues. © 2004 Pearson Addison-Wesley. All rights reserved7 A-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear,
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Queues Chapter 8 (continued)
Data Abstraction & Problem Solving with C++
CC 215 Data Structures Queue ADT
Chapter 13 Queues and Priority Queues
Queues, Deques and Priority Queues
Queues.
Queues, Deques and Priority Queues
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
List Implementations Chapter 9
CS Data Structures Chapter 17 Heaps Mehmet H Gunes
Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Sorted Lists and Their Implementations
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Array-Based Implementations
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Visit for more Learning Resources
CSCS-200 Data Structure and Algorithms
Queues and Priority Queue Implementations
Queues Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Queues.
Queues, Deques, and Priority Queues
Presentation transcript:

Queues and Priority Queues Chapter 13 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Content The ADT Queue Simple Applications of the ADT Queue The ADT Priority Queue Position-Oriented and Value-Oriented ADTs Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

The ADT Queue A queue is like a line of people ADT Queue operations New items enter at the back (rear) of the queue Items leave the queue from the front ADT Queue operations Test whether a queue is empty. Add new entry to back of queue. Remove entry at front of queue Get the entry added earliest to queue. Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

FIGURE 13-1 UML diagram for the class Queue The ADT Queue FIGURE 13-1 UML diagram for the class Queue Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

FIGURE 13-2 Some queue operations The ADT Queue View interface for queues, Listing 13-1 FIGURE 13-2 Some queue operations .htm code listing files must be in the same folder as the .ppt files for these links to work Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Simple Applications of the ADT Queue Reading a string of characters Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Simple Applications of the ADT Queue Recognizing palindromes Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Recognizing Palindromes FIGURE 13-3 The results of inserting the characters a, b, c, b, d into both a queue and a stack Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

The ADT Priority Queue Example : triage in a hospital emergency room Operations Test whether priority queue empty. Add new entry to priority queue in sorted position based on priority value. Remove from priority queue entry with highest priority Get entry in priority queue with highest priority. Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

FIGURE 13-4 UML diagram for the class PriorityQueue The ADT Priority Queue FIGURE 13-4 UML diagram for the class PriorityQueue Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Tracking Your Assignments FIGURE 13-5 UML diagram for the class Assignment Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Tracking Your Assignments Pseudocode for tracking assignments Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Application: Simulation Simulation: technique for modeling behavior of natural and human-made systems. Problem to simulate: model bank queue wait times Average time customer waits to begin service from current single teller Decrease in customer wait time with each new teller added Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Application: Simulation FIGURE 13-6 A bank line at time (a) 0; (b) 20; Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Application: Simulation FIGURE 13-6 A bank line at time (c) 22; (d) 26 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Application: Simulation Results of a simulation: Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Application: Simulation An event-driven simulation considers only times of certain events In this case, arrivals and departures Algorithm Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Application: Simulation FIGURE 13-7 A typical instance of (a) an arrival event; (b) a departure event Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Application: Simulation View final algorithm, Listing 13-A FIGURE 13-8 A trace of the bank simulation algorithm for the data Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Comparison of Stack and Queue Operations Note same task of isEmpty functions push and enqueue similar job pop and dequeue similar tasks Also peek and peekFront Differences are whether function manipulates front or back of ADT Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

ADT List Generalizes Stack and Queue List has getLength insert replicates push and enqueue remove replicates pop and dequeue getEntry replicates peek and peekFront Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

End Chapter 13 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013