ITEC200 Week06 Queues. www.ics.mq.edu.au/ppdp 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type.

Slides:



Advertisements
Similar presentations
ITEC200 Week04 Lists and the Collection Interface.
Advertisements

Chapter 6 Queues and Deques.
ITEC200 Week10 Sorting. pdp 2 Learning Objectives – Week10 Sorting (Chapter10) By working through this chapter, students should: Learn.
Computer Science 112 Fundamentals of Programming II Queues and Priority Queues.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Fundamentals of Python: From First Programs Through Data Structures
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
CHAPTER 4 Queues. Queue  The queue, like the stack, is a widely used data structure  A queue differs from a stack in one important way  A stack is.
CHAPTER 4 Queues MIDTERM THURSDAY, OCTOBER 17 IN LAB.
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.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
ITEC200 – Week08 Trees. 2 Chapter Objectives Students can: Describe the Tree abstract data type and use tree terminology such as.
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 – Week03 Inheritance and Class Hierarchies.
ITEC200 – Week07 Recursion. 2 Learning Objectives – Week07 Recursion (Ch 07) Students can: Design recursive algorithms to solve.
ITEC200 Week01 Introduction to Software Design.
ITEC200 Week02 Program Correctness and Efficiency.
ITEC200 Week05 Stacks. 2 Learning Objectives – Week05 Stacks (Chapter05) Students can Use the methods provided in the public interface.
ITEC200 Week 11 Self-Balancing Search Trees. 2 Learning Objectives Week 11 (ch 11) To understand the impact that balance has on.
CHAPTER 4 Queues. Chapter Objectives  To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface for insertion.
Sets and Maps ITEC200 – Week Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
1 Queues Queue Concept Queue Design Considerations Queues in Java Collections APIs Queue Applications Reading L&C , 9.3.
Queues Chapter 6 Chapter 6: Queues2 Chapter Objectives Learn how to represent a “waiting line”, i.e., a queue Learn how to use the methods in the Queue.
Cmpt-225 Queues. A queue is a data structure that only allows items to be inserted at the end and removed from the front Queues are FIFO (First In First.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
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.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
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.
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.
TCSS 342, Winter 2005 Lecture Notes
Queues, Deques and Priority Queues Chapter 10 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Chapter 6.6, (event-driven simulation) Queues 1CSCI 3333 Data Structures.
Definition Stack is an ordered collection of data items in which access is possible only at one end (called the top of the stack). Stacks are known.
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.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
CHAPTER 4 Queues. Chapter Objectives  To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface for insertion.
Lists Based on content from: Java Foundations, 3rd Edition.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
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.
Data structures Abstract data types Java classes for Data structures and ADTs.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
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:
Overview of Course Java Review 1. This Course Covers, using Java Abstract data types Design, what you want them to do (OOD) Techniques, used in implementation.
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
Chapter Objectives  Learn how to represent a waiting line (queue)  Become proficient using the methods in the Queue  Understand how to implement the.
18-1 Queues Data Structures and Design with Java and JUnit © Rick Mercer.
COMP 121 Week 11: Linked Lists.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Queues Chapter 5 Queue Definition A queue is an ordered collection of data items such that: –Items can be removed only at one end (the front of the queue)
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Data-structure-palooza Checkout DataStructures from SVN.
CH 5 : STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Queues Manolis Koubarakis Data Structures and Programming Techniques 1.
Queue ADT for lining up politely. COSC 2006 queue2 Queue – simple collection class  first-in first-out (FIFO) structure insert new elements at one end.
Queues Chapter 8 (continued)
ADT description Implementations
Queues Queue Concept Queue Design Considerations
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Topic 16 Queues Adapted from Mike Scott’s materials.
THURSDAY, OCTOBER 17 IN LAB
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Chapter 4 Queues.
Queues.
Presentation transcript:

ITEC200 Week06 Queues

2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type and the methods provided in it’s Java implementation (offer, remove, poll, peek and element) Compare and contrast implementations of the Queue interface (single-linked list, double-linked list, circular array) and make augmentations to them Analyse and augment a simulation of a physical system that uses Queues and random number generators Recognise appropriate circumstances to implement queues for data management and simulation purposes

3 Queue Abstract Data Type Queue ADT is an organisation of data whereby insertion occurs at the tail and removal occurs at the head. Can visualize a queue as a line of customers waiting for service The next person to be served is the one who has waited the longest New elements are placed at the end of the line

4 Applications of Queues Operating systems use queues to sequence tasks waiting for a scarce resource –Printer queue –Tasks waiting for CPU Simulation of physical systems uses queues to simulate any ‘first-in first-out’ (FIFO) system –Supermarket checkouts –Tollbooths

5 Specification for a Queue Interface

6 Class LinkedList Implements the Queue Interface The Java 5.0 LinkedList class implements the Queue interface: Queue names = new LinkedList (); creates a new Queue reference, names, that stores references to String objects The actual object referenced by names is type LinkedList Because names is a type Queue reference, you can apply only the Queue methods to it.

7 Case Study: Maintaining a Queue of Customers Class MaintainQueue provides a GUI to perform operations on the queue Algorithms for GUI and for finding the position of a person in the queue are considered

8 Using a Double-Linked List to Implement the Queue Interface Insertion and removal from either end of a double- linked list is O(1) so either end can be the front (or rear) of the queue Java designers decided to make the head of the linked list the front of the queue and the tail the rear of the queue Limitation: LinkedList object is used as a queue, it may be possible to apply other LinkedList methods in addition to the ones required by the Queue interface

9 Using a Single-Linked List to Implement a Queue Can implement a queue using a single-linked list Class ListQueue contains a collection of Node objects

10 Implementing a Queue Using a Circular Array Time efficiency of using a single- or double-linked list to implement a queue is acceptable, however there are some space inefficiencies Implementing a Queue as a Circular Array overcomes space inefficiencies

11 Implementing a Queue Using a Circular Array (continued)

12 Comparing the Three Implementations All three implementations are comparable in terms of computation time Linked-list implementations require more storage because of the extra space required for the links –Each node for a single-linked list stores a total of two references –Each node for a double-linked list would store a total of three references A circular array that is filled to capacity would require half the storage of a single-linked list to store the same number of elements

13 Simulating Waiting Lines Using Queues Simulation is used to study the performance of a physical system by using a physical, mathematical, or computer model of the system Simulation allows designers of a new system to estimate the expected performance before building it Simulation can lead to changes in the design that will improve the expected performance of the new system Useful when the real system would be too expensive to build or too dangerous to experiment with after its construction

14 Case Study: Simulating a Strategy for Serving Airline Passengers

15 Simulate a Strategy for Serving Airline Passengers (continued)

16 Simulate a Strategy for Serving Airline Passengers (continued)

17 Simulating Waiting Lines Using Queues (continued)

18 Simulating Waiting Lines Using Queues (continued)

19 Simulating Waiting Lines Using Queues (continued)

20 Simulating Waiting Lines Using Queues (continued)

21 Simulating Waiting Lines Using Queues (continued)

22 Simulating Waiting Lines Using Queues (continued)

23 Where to from here… Work through Chapter 6 of the Koffman & Wolfgang Text Conceptual Questions and Practical Exercises Submit all preliminary work Be prompt for your online class

24 Acknowledgements These slides were based upon the Objects, Abstraction, Data Structures and Design using Java Version 5.0 Chapter 6 PowerPoint presentation by Elliot B. Koffman and Paul A. T. Wolfgang