Comp 245 Data Structures Queues. Introduction to the Queue ADT It is a FIFO (first-in, first-out) structure Access to the Queue can take place at two.

Slides:



Advertisements
Similar presentations
Chapter 6 Queues and Deques.
Advertisements

Ceng-112 Data Structures I Chapter 5 Queues.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
A queue is an ADT which allows data values to be accessed only one at a time and only the first inserted. The rule imposed on a queue is: First In First.
Fundamentals of Python: From First Programs Through Data Structures
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Data Structures and Algorithms Lecture (Queues) Instructor: Quratulain.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Queues Chapter 6. Chapter Objectives  To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface for insertion.
ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
© 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. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Queues.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
Queues Chapter 6. Chapter 6: Queues2 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface.
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.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
COMP 121 Week 14: Queues. Objectives Learn how to represent a queue Learn how to use the methods in the Queue interface Understand how to implement the.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 2b. Simple Containers: The Queue.
TK1924 Program Design & Problem Solving Session 2011/2012 L6: Queues.
1 CS 132 Spring 2008 Chapter 8 Queues. 2 Queue A data structure in which the elements are added at one end, called the rear, and deleted from the other.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
Computer Science 112 Fundamentals of Programming II Modeling and Simulation.
CSC 205 Programming II Lecture 22 Carwash Simulation.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
Queues Chapter 6. Chapter 6: Queues Chapter Objectives To learn how to represent a waiting line (queue) and how to use the five methods in the Queue interface:
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
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.
Stacks And Queues Chapter 18.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
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)
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.
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
Linear Data Structures
1 Joe Meehean. 2  empty is the queue empty  size  enqueue (add) add item to end of queue  dequeue (remove) remove and return item at front of queue.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
CH 5 : STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Circular Queues Maitrayee Mukerji. Queues First In – First Out (FIFO) The first element to be inserted is the first one to be retrieved Insertion at one.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 2b. Simple Containers: The Queue.
Queues Chapter 8 (continued)
Review Array Array Elements Accessing array elements
Data Structures Using C++ 2E
Queues.
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Queues Queues Queues.
Algorithm and Data Structure Part III Dr. Naimah Yaakob
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Queues What is a Queue? Queue Implementations: As Array
CE 221 Data Structures and Algorithms
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
CSC 248 – fundamentals of Data structure
CSCS-200 Data Structure and Algorithms
Data Structures & Programming
Presentation transcript:

Comp 245 Data Structures Queues

Introduction to the Queue ADT It is a FIFO (first-in, first-out) structure Access to the Queue can take place at two locations: 1) the Front for data removal and 2) the Rear for data storage No access to elements other than the Front and Rear

Abstract View of a Queue

A RRRRRobust Queue Full The Full() function will be used in conjunction with Enqueue Empty The Empty() function will be used in conjunction with Dequeue

Queue Application Drive-In Teller Simulation Computers are excellent for simulating real- life situations. Queuing (Line) simulation software is available to observe a key behavior – WAIT TIME for a customer. Running this simulation can help a business determine how many lines to have open at certain times during the day in order to achieve an acceptable wait time for customers. Also, this helps tellers (servicers) to be productive.

Queue Application Drive-In Teller Simulation The Drive-In Teller Simulation will model a single-server, single-queue situation. We must obtain the following information before we run the simulation o Length of simulation o Arrival rate probability of a customer o Expected service time  The output from the simulation will be average wait time for a customer.

Queue Application Drive-In Teller Simulation Queuing Equations AR = Arrival Probability, ST = Service Time 1) (AR)(ST) < 1(STABLE) 2) (AR)(ST) > 1(UNSTABLE) 3) (AR)(ST) = 1(FLUCUATING)

Queue Application Drive-In Teller Simulation How do we represent a clock? A counter variable How do we determine if a customer has arrived in line? A random number generator will dictate an enqueue. How do we represent a teller? A counter variable How do we represent a customer? A timestamp How do we determine how long a customer has waited? Subtract timestamp from current time on clock How does a customer get out of line to be serviced? When the teller becomes available and the queue is not empty a dequeue is executed. How do we determine average wait time for a customer? Total wait time accumulation/Total customers served

Implementing a Queue ADT Array Based There are three different types of array based Queues: o Packing o Circular o Free-Space  The three differ in… o The number of control fields needed to maintain the queue o How they enqueue and dequeue o How they determine if the queue is empty or full

Implementing a Queue ADT Array Based - Packing Needs an array(A) and a count(C) to implement. Enq – data will be added to the queue at A[C] Deq – data will be removed from the queue at A[0]; IMPORTANT: after a Deq, array must be packed! Full – (C == MAX) Empty- (C == 0)

Packing Queue Example

Implementing a Queue ADT Array Based - Circular Needs an Array(A), Count(C), Front(F) and a Rear(R) to implement. Enq – will add data to A[R], after the Enq, R must be incremented or wrapped. That is R++ or R = 0. Count must be incremented. Deq – will remove data from A[F], after the Deq, F must be incremented or wrapped. That is F++ or F = 0. Count must be decremented. Empty – (C = = 0) Full – (C == MAX)

Circular Queue Example Part I

Circular Queue Example Part II

Implementing a Queue ADT Array Based – Free Space Needs an Array(A), Front(F) and a Rear(R) to implement. Initially set F and R to the last slot in the array. Enq – You will increment or wrap R first and then add data to A[R] Deq – You will increment or wrap F first and then remove data from A[F] Empty – (F = = R) Full – (F == R+1 or F == wrap(R)) “THIS PROTECTS EMPTY CONDITION”

Free Space Queue Example Part I

Free Space Queue Example Part II

Static Queue Review Packing Enq – A[C] Deq – A[0] Full – (C==Max) Empty – (C==0) Circular Enq – A[R++] Deq – A[F++] Full – (C==Max) Empty – (C==0) Free Space Enq – A[++R] Deq – A[++F] Full – (F==R+1) Empty – (F==R)

Implementing a Queue ADT Linked List Based Requires two pointers: 1) Front and 2) Rear There is a “special” condition on Enq: Enq when the Queue is empty. There is a “special” condition on Deq: Deq when the Queue has only one element.

Enq with a Linked List

Deq with a Linked List

Queue Implementation Review Array Based o Packing (counter) o Circular (counter, front, rear) o Free Space (front, rear) Linked List Based o Need only a front and rear pointer o Must handle special cases for enq and deq

C++ STL Queue Container Class The STL queue is a type of container specifically designed to operate in a FIFO context (first-in first- out), where elements are inserted into one end of the container and extracted from the other. Here is an example of STL queue usage: queueSTL.cpp