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:

Slides:



Advertisements
Similar presentations
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Advertisements

Chapter 6 Queues and Deques.
ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues.
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
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.
Stacks Chapter 5. Chapter Objectives  To learn about the stack data type and how to use its four methods: push, pop, peek, and empty  To understand.
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.
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.
Stacks Chapter 5. Chapter 5: Stacks2 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop, peek, and empty.
© 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 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.
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
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Building Java Programs
Chapter 6.6, (event-driven simulation) Queues 1CSCI 3333 Data Structures.
EXPANDING STACKS AND QUEUES CS16: Introduction to Data Structures & Algorithms 1 Tuesday, February 10, 2015.
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.
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
© 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.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
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.
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
PRIORITY QUEUES AND HEAPS Slides of Ken Birman, Cornell University.
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)
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Linear Data Structures
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
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.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Stacks and Queues. 2 Abstract Data Types (ADTs) abstract data type (ADT): A specification of a collection of data and the operations that can be performed.
CE 221 Data Structures and Algorithms
Chapter 15 Lists Objectives
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Monday, February 26, 2018 Announcements… For Today…
Building Java Programs
structures and their relationships." - Linus Torvalds
THURSDAY, OCTOBER 17 IN LAB
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.
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Chapter 4 Queues.
CE 221 Data Structures and Algorithms
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
structures and their relationships." - Linus Torvalds
Chapter 6 – Queues and Deques
Presentation transcript:

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: insert, retrieve, peek, getSize, and isEmpty To understand how to implement the Queue interface using a single-linked list, a circular array, and a double- linked list To understand how to simulate the operation of a physical system that has one or more waiting lines using Queues and random number generators

Chapter 6: Queues Queue Abstract Data Type 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

Chapter 6: Queues Queue Abstract Data Type (continued)

Chapter 6: Queues A Print Queue Operating systems use queues to Track of tasks waiting for a scarce resource To ensure that the tasks are carried out in the order that they were generated Print queue: printing is much slower than the process of selecting pages to print and so a queue is used

Chapter 6: Queues A Print Queue (continued)

Chapter 6: Queues The Unsuitability of a Print Stack Stacks are last-in, first-out (LIFO) The most recently selected document would be the next to print Unless the printer queue is empty, your print job may never get executed if others are issuing print jobs

Chapter 6: Queues Using a Queue for Traversing a Multi- Branch Data Structure A graph models a network of nodes, with many links connecting each node to other nodes in the network A node in a graph may have several successors Programmers often use a queue to ensure that nodes closer to the starting point are visited before nodes that are farther away

Chapter 6: Queues Specification for a Queue Interface

Chapter 6: Queues Maintaining a Queue of Customers Queue is good for storing a list of customers as they should be serviced in the order in which they arrived Algorithm for processCustomers While the user is not finished Display the menu and get the operation selected Perform the operation selected

Chapter 6: Queues Maintaining a Queue of Customers (continued)

Chapter 6: Queues Maintaining a Queue of Customers (continued)

Chapter 6: Queues Using a Single-Linked List to Implement a Queue Can implement a queue using a single-linked list Insertions are at the rear of a queue and removals are from the front Need a reference to the last list node Number of elements in the queue is changed by methods insert and remove

Chapter 6: Queues Using a Single-Linked List to Implement a Queue (continued)

Chapter 6: Queues Implementing a Queue Using Java’s LinkedList Can be implemented as an adapter of any class that implements the List interface ArrayList Vector LinkedList Removal is O(n) with a linked list O(n) when using ArrayList or Vector

Chapter 6: Queues 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 Storage space is increased when using a linked list due to references stored at each list node Array Implementation Insertion at rear of array is constant time Removal from the front is linear time Removal from rear of array is constant time Insertion at the front is linear time

Chapter 6: Queues Implementing a Queue Using a Circular Array (continued)

Chapter 6: Queues Implementing a Queue Using a Circular Array (continued)

Chapter 6: Queues Implementing a Queue Using a Circular Array (continued)

Chapter 6: Queues Implementing a Queue Using a Circular Array (continued)

Chapter 6: Queues 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 would store 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

Chapter 6: Queues 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

Chapter 6: Queues Simulating Waiting Lines Using Queues (continued) System designers often use computer models to simulate physical systems Airline check-in counter for example A special branch of mathematics called queuing theory has been developed to study such problems

Chapter 6: Queues Simulate a Strategy for Serving Airline Passengers

Chapter 6: Queues Simulate a Strategy for Serving Airline Passengers (continued)

Chapter 6: Queues Simulate a Strategy for Serving Airline Passengers (continued)

Chapter 6: Queues Simulating Waiting Lines Using Queues (continued)

Chapter 6: Queues Simulating Waiting Lines Using Queues (continued)

Chapter 6: Queues Simulating Waiting Lines Using Queues (continued)

Chapter 6: Queues Simulating Waiting Lines Using Queues (continued)

Chapter 6: Queues Chapter Review Queue is an abstract data type with a first-in, first-out structure (FIFO) The Queue interface declares methods insert, remove, peek, size, and isEmpty Three ways to implement the Queue interface: single- linked list, circular array, and as an adapter of the LinkedList class To avoid the cost of building a physical system or running an actual experiment, computer simulation can be used to evaluate the expected performance of a system or operation strategy