Chapter 6 Queue. Learning Objectives ● Describe the behavior of a queue. ● Enumerate the primary operations supported by a queue. ● Learn about the UNIX.

Slides:



Advertisements
Similar presentations
Computer Science 112 Fundamentals of Programming II Queues and Priority Queues.
Advertisements

Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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.
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.
ADT Queue 1. What is a Queue? 2. STL Queue 3. Array Implementation of Queue 4. Linked List Implementation of Queue 5. Priority Queue.
Fundamentals of Python: From First Programs Through Data Structures
Data Structure Dr. Mohamed Khafagy.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Advanced Data Structures
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.
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.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
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.
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.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
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 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
Chapter 24 Dispensers and dictionaries. This chapter discusses n Dictionaries n Dispensers u stacks u queues u priority queues.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
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 7 Stack. Overview ● The stack data structure uses an underlying linear storage organization.  The stack is one of the most ubiquitous data structures.
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)
Queues Chapter 3. Objectives Introduce the queue abstract data type. – Queue methods – FIFO structures Discuss inheritance in object oriented programming.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
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.
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:
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
Stacks And Queues Chapter 18.
Implementation of QUEUE For more notes and topics visit: eITnotes.com.
The Abstract Data Type Queue A queue New items enter at the back, or rear, of the queue Items leave from the front of the queue First-in, first-out (FIFO)
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.
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.
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.
Copyright © Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
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.
Queues Another Linear ADT Copyright © 2009 Curt Hill.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
1 Chapter 4 Unordered List. 2 Learning Objectives ● Describe the properties of an unordered list. ● Study sequential search and analyze its worst- case.
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
Queues Chapter 8 (continued)
Review Array Array Elements Accessing array elements
Data Abstraction & Problem Solving with C++
Chapter 6 Queue.
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.
CC 215 Data Structures Queue ADT
Chapter 6 Queue.
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Queues Queues Queues.
Principles of Computing – UFCFA3-30-1
DATA STRUCTURE QUEUE.
Chapter 7 Stack.
CSC 143 Queues [Chapter 7].
Chapter 6 Queue.
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 6 Queue.
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Queues.
Presentation transcript:

Chapter 6 Queue

Learning Objectives ● Describe the behavior of a queue. ● Enumerate the primary operations supported by a queue. ● Learn about the UNIX print queue, the main commands that con be issued to it, and how these commands may be mapped to the operations of the queue data structure. ● Understand the public interface of a queue class in Java and the running times of its methods.

Learning Objectives ● Implement a print queue class in Java using the queue class. ● Study the implementation of the queue class, and the trade-offs involved in choosing between candidate storage components.

6.1 Queue Properties ● Queues  Lines in which people “queue” up to be served, in a first come, first served manner.  The typical computing environment queues are used to process requests for service on shared resources. ● Printer uses a first-come first-served policy. ● First served policy is also known as first in, first out, or FIFO for short.

6.1 Queue Properties

● The FIFO policy is applicable only for entries that reach the front of the queue and are then removed.  Entries may leave the queue without reaching the front.

6.1 Queue Properties

Floating-Front Design Approach

The Enqueue Operation

The Dequeue Operation

6.2 UNIX Print Queue ● The UNIX lpr command enqueues a print job. ● lpq checks the status of the printer queue. ● First entry is currently being printed (active).

6.2 UNIX Print Queue  Deletes the job that is currently active (being printed). ●  Removes all the jobs.

6.3 A Queue Class

● A queue can be considered a specialized (restricted) unordered list. ● All methods supported by Queue have their functional counterpart in the List class.  Exception:dequeue and postionOf.  Enqueue is identical in functionality to add.  All other methods have identical names between both classes.

6.3 A Queue Class ● An efficient implementation would maintain a direct reference to the rear and another to the front.  Enqueue and dequeue can be implemented in O(1) time.  Maintains a running count of the number of entries in the queue. ● The methods size and isEmpty can be implmented in O(1).

6.4 A PrintQueue Class Using Queue

● Job class hierarchy  A basic Job class that stands for the type of all objects in the queue.  OwnerJob class compares owner names.  OwnerIdJob class compares owner names and job ids.

6.4 A PrintQueue Class Using Queue

● toString and equals are both declared public.  These methods override their Object class counterparts. (dynamic binding  the object type will determine which method to exec.)  Ex: ● Class A: Base ● Class B : subclass of A ● A and B have p method ● A a = new A(); ● B b = new B(); ● a = b; ● a.p();  method p of class B will be exec,

6.4 A PrintQueue Class Using Queue

6.5 Queue Class Implementation ● Array list  Front and rear are maintained to point to the respective ends of the queue.

6.5 Queue Class Implementation

● Every enqueue and dequeue pair results in array location being wasted. ● Circular Array  When the queue wraps back, the rear index becomes less than the front index.  If the rear index is less than the front index, then the gap between the rear and front is the unused space.  Compute the used space by subtracting this unused space from the length of the array. ● front - rear -1

6.5 Queue Class Implementation

● In an empty queue, the rear index is one less than the front index.  If the queue is filled and the rear index keeps advancing until it ends up coming to one position behind the front index, it looks the same as the empty queue.  Keeping a count of the number of entries in the queue, starting with 0 when the queue is created resolves this ambiguity.

6.5 Queue Class Implementation

6.5.2 Design 2: Using Linked List

6.6 Summary ● The queue data structure implements the First In First Out (FIFO) abstraction. ● A queue is a linear collection of entires in which, for every pair of entries x and y, if x leaves from the front of the queue before y, then x must have entered the queue before y. ● An entry may leave a queue before reaching the front.  In this case, that entry is not served.

6.6 Summary ● There are two fundamental operations supported by a queue: enqueue and dequeue. ● A queue class may provide more than just the fundamental enqueue and dequeue operations to facilitate ease of use. ● A queue may be viewed as a specialized or restricted unordered list. ● A print queue in UNIX can be implemented using the queue data structure.

6.6 Summary ● Implementing a UNIX print queue using the Queue class requires the Queue clients to build a class hierarchy that will enable the matching of a queue entry against a specific item based on either job id, job owner, or both. ● If class B extends class A, then any method in B that overrides an inherited method from A cannot be less accessible than the inherited method.

6.6 Summary ● An array list may be used to implement the queue, but this would result in a implementation that is either inefficient in time or wasteful of space usage. ● A circular array may be used to implement a queue, with the attendant problem of overestimating or underestimating the space requirement associated with the static allocation of an array.

6.6 Summary ● A linked list is better than either an array list or a circular array to implement the queue. ● When class A reuses an instance of class B as a component, exceptions thrown by methods of B may have to be caught by A in order to reinterpret them for clients of A.