Queues. From last time: Java's built-in java.util.Stack class Consider the javadoc for Java’s built-in java.util.Stack class (http://download.oracle.com/javase/7/docs/api/java/u.

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

Stacks, Queues, and Linked Lists
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues.
1 Queues (Continued) Applications for a queue Linked queue implementation Array queue implementation Circular array queue implementation Reading L&C 3.
Topic 9 The Queue ADT.
CHAPTER 7 Queues.
Fundamentals of Python: From First Programs Through Data Structures
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues.
Chapter 7 Queues. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Examine queue processing Define a queue abstract.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 4.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
CS Data Structures II Review COSC 2006 April 14, 2017
Queues and Priority Queues
Chapter 13 Queues and Priority Queues CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Searching and Sorting. Overview Search Analysis of search algorithms Sorting Analysis of sort algorithms Recursion p. 2 of 26.
Priority Queues and Heaps. Overview Our last ADT: PriorityQueueADT A new data structure: heaps One more sorting algorithm: heapsort Priority Queues and.
© 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.
Chapter 12: Data Structures
Linked structures. Overview Overview of linked structures (for lists) Design decision: arrays vs. linked lists Implementing the StackADT with linked lists.
OrderedListADT. Overview OrderedListADT: not the same as linked lists The OrderedListADT: operations and sample applications An ArrayList implementation.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
TCSS 342, Winter 2005 Lecture Notes
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Chapter 14 Queues. First a Review Queue processing Using queues to solve problems – Optimizing customer service simulation – Ceasar ciphers – Palindrome.
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
Queues and Priority Queues
Chapter 7 Queues. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-2 Chapter Objectives Examine queue processing Define a queue abstract.
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.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
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)
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Stacks and Queues Introduction to Computing Science and Programming I.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
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:
Clicker questions and stuff 12/5/13 CSE 1102 Fall 2013.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Stacks And Queues Chapter 18.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 5: Queues Java Software Structures: Designing and Using Data.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
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.
(c) , University of Washington19a-1 CSC 143 Stacks and Queues: Concepts and Implementations.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
April 27, 2017 COSC Data Structures I Review & Final Exam
1 Queues (Continued) Queue ADT Linked queue implementation Array queue implementation Circular array queue implementation Deque Reading L&C , 9.3.
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
The Queue ADT.
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Unit 4 Stacks And Queues King Fahd University of Petroleum & Minerals
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Lecture 7 Queues Stacks Trees.
Chapter 12: Data Structures
Queues Queue Concept Queue Design Considerations
Stacks and Queues.
Stack and Queue APURBO DATTA.
Building Java Programs
CMSC 341 Lecture 5 Stacks, Queues
CSC 143 Queues [Chapter 7].
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.
DATA STRUCTURES IN PYTHON
Presentation transcript:

Queues

From last time: Java's built-in java.util.Stack class Consider the javadoc for Java’s built-in java.util.Stack class ( til/Stack.html). What are the design flaws in this class? Explain. Hint: can it guarantee that the item you pop will always be the last item pushed? Queues p. 2/19

Overview What are queues useful for? The QueueADT interface LinkedQueue implementation Time complexity of LinkedQueue operations Array implementations Application: ticket counter Queues vs. stacks Coming attractions Queues p. 3/19

What are queues useful for? Suppose we want to model: A. Customers waiting in line for an online helpdesk B. Print jobs waiting for the printer C. Customers waiting in line at a bank Assuming no one cuts in line, what operations would the solutions to these problems have in common? Queues p. 4/19

Now contrast the following: A. The undo operation in Word B. The Back button in a web browser C. A hundred names in alphabetical order, where names are added and removed frequently D. The roads and intersections in a city Would our queue operations help to solve these problems? Why or why not? Queues p. 5/19

You try … Give three everyday examples of a situation that could be modeled using a queue. Queues p. 6/19

The QueueADT interface Consider the code p. 102 Compare the operations given here with those we listed. Queues p. 7/19

The QueueADT interface In the code on page 102, the capital letter “T” stands for: A. a temporary value B. the type of the items in the Queue C. a class named T defined somewhere else in the program D. the top of the Queue E. none of the above Queues p. 8/19

A LinkedQueue implementation Consider the start of the implementation on the top of page 114. What's the overall purpose? And what is each line there for? Queues p. 9/19

A LinkedQueue implementation Consider the LinkedQueue code on pp What happens when client code tries to enqueue an item? Describe precisely with box and arrow diagrams and reference to particular lines of code. Queues p. 10/19

Time Complexity of LinkedQueue Consider the LinkedQueue code on pp The Big-Oh time complexity of the enqueue operation is: A. O(1) B. O(log 2 n) C. O(n) D. O(n 2 ) E. none of the above Queues p. 11/19

Time Complexity of LinkedQueue Consider the LinkedQueue code on pp The Big-Oh time complexity of the dequeue operation is: A. O(1) B. O(log 2 n) C. O(n) D. O(n 2 ) E. none of the above Queues p. 12/19

Time Complexity of LinkedQueue Consider the LinkedQueue code on pp What is the Big-Oh time complexity of the other Queue operations? Queues p. 13/19

Array implementations Draw a picture of an 8-element array. Insert the characters A, B, C, D, E into the first five locations of the array. Suppose A is the front of a queue and E is the rear. Dequeue 3 elements and then add 4. What happens? Queues p. 14/19

Possible solution: “circular” arrays How would these solve our problem? Describe precisely using the example above. How do they compare with the linked list implementation of queues? What are the advantages and limitations of each? Queues p. 15/19

Application: ticket counter (In groups) Consider the ticket counter simulation problem and the solution given in the text (pp ). Hand trace the solution for 22 customers and 4 cashiers. Queues p. 16/19

Queues vs. stacks Match each stack operation with the related queue operation: A. push1. isEmpty B. pop2. enqueue C. peek3. dequeue D. isEmpty4 toString E. toString5. front Queues p. 17/19

Queues vs. stacks Which operations work the same even though they may have different names? Which work differently? (Answer with reference to specific lines of code. If no code is given in the book, explain how you would implement the operation). A. push1. isEmpty B. pop2. enqueue C. peek3. dequeue D. isEmpty4 toString E. toString5. front Queues p. 18/19

Coming attractions Next time we'll look at our third Abstract Datatype, ListADT, a new linear data structure that allows elements to be added at the beginning, the end, and the middle. Homework: read Chapter 6 Lists (or the equivalent in the earlier edition). Queues p. 19/19