Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 4.

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)
Queues1 Part-B2 Queues. Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out scheme.
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.
ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and 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.
Stacks and Queues. 2 Stack and Queue ADT’s You should understand How are they different philosophically from arrays What are they used for How do you.
Queues CS-212 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed in their.
CHAPTER 7 Queues.
Fundamentals of Python: From First Programs Through Data Structures
Data Structure Dr. Mohamed Khafagy.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
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.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
Queue, Deque, and Priority Queue Implementations.
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.
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
Queues What is a Queue? Queue Implementations: Queue As Array
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Queues and Priority Queues
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
© 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,
Queues, Deques, and Priority Queues Chapter 23 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
1 Stacks and Queues Starring: IndexOutOfBOundsException Co-Starring: NoSuchElementException.
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
Chapter 8 Queue I CS Data Structures I COSC2006 April 24, 2017
CSE373: Data Structures & Algorithms Lecture 6: Priority Queues Dan Grossman Fall 2013.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 3.
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.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
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.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
April 27, 2017 COSC Data Structures I Review & Final Exam
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.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Queues Another Linear ADT Copyright © 2009 Curt Hill.
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
Review Array Array Elements Accessing array elements
CC 215 Data Structures Queue ADT
Stacks and Queues.
Queues Queues Queues.
CMSC 341 Lecture 5 Stacks, Queues
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues, Deques and Priority Queues
Queue, Deque, and Priority Queue Implementations
Queues 11/16/2018 4:18 AM Queues 11/16/2018 4:18 AM Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
CSC 143 Queues [Chapter 7].
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
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.
Queues CSC212.
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
CSCS-200 Data Structure and Algorithms
Queues, Deques, and Priority Queues
Presentation transcript:

Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 4

 Definition of Queues  Operators for Queues  Insert  Remove  Peek  Special Queues  Circular Queues  Priority Queues  Efficiency of Queues

 A Queue is a First-In-First-Out(FIFO) abstract data structure.  In a Queue, new item insert to the rear and the item in the front will be removed first Rear Front

 A queue is similar to a stack, except that you join the queue at one end and leave it at the other.  We shall again use an array to storing the items in the queue.  We shall need two pointers, one to indicate where the next item to be placed in the queue should be stored (rear), and another to indicate the location of the next item to be retrieved (front).

Fig.1 Bus Queue: A Typical Queue

7 Abstract Data Type (ADT): don’t care about how to realize, just use it. public interface QueueInterface { /** Task: Add item to back */ public void enqueue(Object newEntry); /** Task: Removes and returns the front */ public Object dequeue(); /** Task: Retrieves front of queue without removing */ public Object getFront(); /** Task: Determines whether the queue is empty.*/ public boolean isEmpty(); /** Task: Removes all entries from the queue. */ public void clear(); }

8 Queue of strings after (a) enqueue adds Jim; (b) Jess; (c) Jill; (d) Jane; (e) Joe; (f) dequeue retrieves, removes Jim; (g) enqueue adds Jerry; (h) dequeue retrieves, removes Jess.

 Single queue, single server  Single queue, multiple servers:  Improve processes, e.g., most banks use a snake queue instead individual lines at each teller.  2 queues, 2 servers vs. 1 queue, 2 servers ▪ Increase utilization ratio  Electronic Queuing System (see animation)  Multiple queues, single server  Intersection Management byTraffic Light (see animation)  Multiple queues, multiple servers

 Customers who intended to join the line but don’t  Customers who join, then leave  Jumping from queue to queue  Jumping to newly opened line  Follow the employee  Two line strategy (bring spouse or kids), then merge into a faster queue See Animation

 People hate to wait in queues – shorter queues may result in increased efficiency.  Some customers leave shopping carts full of groceries at the checkout counters and frozen and cold food are wasted.

 Insert: insert a data item to the rear of the queue Fig.2 Insert Operator in Queues Front Rear

Program  Remove: Remove a data item at the front of the queue Fig.3 Remove Operator in Queues Front Rear

Program  Peek: Get a data item at the front of the queue without removing Fig.4 Peek Operator in Queues Front Rear

 Circular Queues  We shall treat the underlying array as a circular buffer.  Problem Statement Front Rear No Space Rear Fig.5 Insertion of Circular Queues

 Items to be enqueued will be written in the array at queue[rear].  Items to be dequeued will be read from queue[front].  After each writing, top is incremented by one.  After each reading, rear is incremented by one.  Incrementing of rear and front is always modulo queue.length.

 The priority queue is a data structure that only allows access to the “minimum” item in a set.

 Discrete event simulation (desired simulation time is used to set priorities)

 The items in Priority Queue has priority  Insertion in Priority Queue is different Fig.6 Insertion of Priority Queues Front Rear

 Goals: fast findMin, deleteMin, insert  findMin: Identify entry whose key is lowest  deleteMin: remove entry whose key is lowest  Insert: any entry may be inserted at any time  How should we implement a priority queue?  Option 1: a linked list  Option 2: a sorted linked list  Option 3: a binary search tree  Option 4: a balanced binary search tree

 Starving  When items with higher priority are inserted into the queue, the items with lower priority will be starved  Fairness problems should be considered

 In conventional queues, items can be both pushed and popped from a stack in constant O(1) time  For priority queues, insertion runs in O(N) time, whereas deletion takes O(1) time