Chapter 6.6, 16 + 13.2 (event-driven simulation) Queues 1CSCI 3333 Data Structures.

Slides:



Advertisements
Similar presentations
Queues A waiting line that grows by adding elements to its end and shrinks by taking elements from its front Line at the grocery store Cars in traffic.
Advertisements

Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
IKI 10100I: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100I: Data.
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.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
CHAPTER 4 Queues MIDTERM THURSDAY, OCTOBER 17 IN LAB.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 4.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
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.
1 Queues Queue Concept Queue Design Considerations Queues in Java Collections APIs Queue Applications Reading L&C , 9.3.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
Queue, Deque, and Priority Queue Implementations Chapter 24 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
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
CSC 212 Stacks & Queues. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  Cannot force you to compile & test.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
Queue, Deque, and Priority Queue Implementations Chapter 11 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Queues, Deques and Priority Queues Chapter 10 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Chapter 16 Stacks and Queues Saurav Karmakar Spring 2007.
Chapter 14 Queues. First a Review Queue processing Using queues to solve problems – Optimizing customer service simulation – Ceasar ciphers – Palindrome.
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.
Chapter 6.6, 11, 16 Stacks 1CSCI 3333 Data Structures.
Chapter 16 Stacks & Queues. Objective In this chapter we will learn:  Stacks  Queues  Different implementations (arrays and linked list) of both 
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
© A+ Computer Science - A queue is a group of same-type values. Values are added to the back of a queue and removed from the front.
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:
LECTURE 26: QUEUES CSC 212 – Data Structures. Using Stack.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture6.
Week 3 - Friday.  What did we talk about last time?  Stacks  Array implementation of a stack.
Chapter Objectives  Learn how to represent a waiting line (queue)  Become proficient using the methods in the Queue  Understand how to implement the.
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.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
Question of the Day  Three people check into a hotel for which they pay the manager $30. The manager finds out the rate is $25 and gives $5 to the bellboy.
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.
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Week 5 - Wednesday.  What did we talk about last time?  Recursion  Definitions: base case, recursive case  Recursive methods in Java.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Topic 16 Queues "FISH queue: n. [acronym, by analogy with FIFO (First In, First Out)] ‘First In, Still Here’. A joking way of pointing out that processing.
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Chapter 6.6, 11, 16 Stacks 1CSCI 3333 Data Structures.
 2015, Marcus Biel, Linked List Data Structure Marcus Biel, Software Craftsman
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.
Week 15 – Monday.  What did we talk about last time?  Tries.
Week 4 - Monday CS221.
Lecture 7 Queues Stacks Trees.
Csc 2720 Data structure Instructor: Zhuojun Duan
Chapter 12: Data Structures
Topic 16 Queues Adapted from Mike Scott’s materials.
Queues, Deques and Priority Queues
Queue, Deque, and Priority Queue Implementations
Queue, Deque, and Priority Queue Implementations
Queues, Deques and Priority Queues
CSC 143 Queues [Chapter 7].
More Data Structures (Part 1)
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Queue, Deque, and Priority Queue Implementations
Presentation transcript:

Chapter 6.6, (event-driven simulation) Queues 1CSCI 3333 Data Structures

Outline Intro. to Queues java.util.Queue interface Example programs CSCI 3333 Data Structures2

3 Queue Typical application of Queue: A collection designed for holding elements prior to processing. Supported operations: – enqueue (n): add n at the back of the queue – dequeue( ): remove the object at the front /head of the queue and return that object – getFront( ): aka. element( ), peek( ) return the object at the front of the queue (w/o removing it from the queue) All three operations take constant time.

Queues Special features: (typically) First in, first out (FIFO) - dequeue( ) and getFront( ) returns the least recently added item in the queue. Exceptions: priority queues Items in a priority queue are ordered according to some criteria (example: in OS, types of the processes, user privileges, etc.) CSCI 3333 Data Structures4

Applications of Queue In any computer applications that need to deal with a waiting list of something. e.g., In operating systems: A process queue collects processes that are waiting to use the processor or other system resources. e.g., In event-driven simulation: A priority queue stores the list of events that need to be handled by the simulator. e.g., ? CSCI 3333 Data Structures5

Implementation of Queue A Queue may be implemented as an Array or a Linked List. as a dynamic array: – ArrayQueue.java (Figure 16.8 – 16.17) private AnyType [ ] theArray; private int currentSize; private int front; private int back; private static final int DEFAULT_CAPACITY = 10; CSCI 3333 Data Structures6

7

8

Implementation of Queue as a linked list: – ListQueue.java (Figure – 16.27) See plesandRelatedTopics.htm#queues for an example testing program. plesandRelatedTopics.htm#queues CSCI 3333 Data Structures9

10

Interface: java.util.Queue Interface Queue CSCI 3333 Data Structures11

Array-based queues vs LinkedList-based queues CSCI 3333 Data Structures12 OperationsLinkedList-based Queues (L)Array-based Queues (A) Run timeBoth run in constant time per operation. Space costLess space. Allocated when a new node is added. Estimated space requirement. Doubling the array takes up extra space. Sequential access L is not as efficient as A. Code complexity A is more complicated than L, owing to codes for wraparound and array doubling.

Double-Ended Queues (deque) A queue that allows access at both ends. Enqueue  addFront, addRear Dequeue  removeFront, removeRear In Java: – java.util.Deque interface – Class ArrayDeque – The LinkedList class can be used as a stack, queue, or deque, because it implements both the List and the Deque interfaces. CSCI 3333 Data Structures13