Chapter 6 Queue.

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)
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.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 6 Queue. Learning Objectives ● Describe the behavior of a queue. ● Enumerate the primary operations supported by a queue. ● Learn about the UNIX.
Data Structure Dr. Mohamed Khafagy.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
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.
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.
Chapter 24 Dispensers and dictionaries. This chapter discusses n Dictionaries n Dispensers u stacks u queues u priority 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 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)
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
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.
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)
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.
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.
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
Chapter 5 Ordered List.
Data Abstraction & Problem Solving with C++
CSE373: Data Structures & Algorithms
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.
COSC160: Data Structures: Lists and Queues
CC 215 Data Structures Queue ADT
Queues Rem Collier Room A1.02
Chapter 6 Queue.
Csc 2720 Data structure Instructor: Zhuojun Duan
CSE 373: Data Structures and Algorithms
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.
Stacks and Queues.
Chapter 7 Stack.
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.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Priority Queues & Heaps
Chapter 4 Queues.
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
CSCS-200 Data Structure and Algorithms
Queues Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks and Queues.
Queues.
Data Structures & Programming
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

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

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 the job whose id is jobid. Removes all the jobs.

6.3 A Queue Class

6.3 A Queue Class

6.3 A Queue Class

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

6.4 A PrintQueue Class Using Queue

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

6.4 A PrintQueue Class Using Queue

6.4 A PrintQueue Class Using Queue

6.4 A PrintQueue Class Using Queue toString and equals are both declared public. These methods override their Object class counterparts.

6.4 A PrintQueue Class Using Queue

6.4 A PrintQueue Class Using Queue

6.4 A PrintQueue Class Using Queue

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

6.5 Queue Class Implementation

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

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.5.2 Design 2: Using Linked List

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.