Queues By Jimmy M. Lu. Overview Definition Standard Java Queue Operations Implementation Queue at Work References.

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Queues and Linked Lists
1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
A queue is a linear, homogeneous, container that stores and dispenses its content in a FIFO manner. FIFO - First In First Out The first (most distant)
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.
1 Queues – Chapter 3 A queue is a data structure in which all additions are made at one end called the rear of the queue and all deletions are made from.
CHAPTER 7 Queues.
Data Structure Dr. Mohamed Khafagy.
Queue Overview Queue ADT Basic operations of queue
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Queues.
Queues What is a queue? Queue Implementations: –As Array –As Circular Array –As Linked List Applications of Queues. Priority queues.
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.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Lecture7: Queue Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Stacks And Queues Chapter 18.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Queue. Avoid confusion Britain Italy 6 Applications of Queues Direct applications –Waiting lists, bureaucracy –Access to shared resources (e.g.,
Chapter 7 Queues Introduction Queue applications Implementations.
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
Queue. The Queue ADT Insertions and deletions follow the first-in first-out scheme Insertions are at the rear of the queue and removals are at the front.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
1 Queues (Continued) Queue ADT Linked queue implementation Array queue implementation Circular array queue implementation Deque Reading L&C , 9.3.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Queues1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
CS505 Data Structures and Algorithms
Queues.
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
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.
Queues Rem Collier Room A1.02
CSE 373: Data Structures and Algorithms
Queue data structure.
Stacks and Queues.
Queues Queues Queues.
Queues What is a queue? Queue Implementations: As Array
CMSC 341 Lecture 5 Stacks, Queues
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues 11/9/2018 6:32 PM Queues.
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.
Circular queue.
Queues.
Queue.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
COMPUTER 2430 Object Oriented Programming and Data Structures I
CSC 143 Queues [Chapter 7].
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
Queues 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Queues What is a Queue? Queue Implementations: As Array
Queues Jyh-Shing Roger Jang (張智星)
Copyright © Aiman Hanna All rights reserved
ADT Queue (Array Implementation)
Visit for more Learning Resources
CE 221 Data Structures and Algorithms
Queues Definition of a Queue Examples of Queues
Getting queues right … finally (?)
Queues What is a queue? Queue Implementations: As Array
The Queue ADT Definition A queue is a restricted list, where all additions occur at one end, the rear, and all removals occur at the other end, the front.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Data Structures & Programming
Presentation transcript:

Queues By Jimmy M. Lu

Overview Definition Standard Java Queue Operations Implementation Queue at Work References

Definition A Queue is a data structure which stores items in a FIFO manner –FIFO stands for First In First Out. –Examples: A queue of people waiting in a line. A queue of documents waiting for the printer An abstract Queue is a queue where the elements can only be removed by the ‘dequeue’ operation

Standard Java Queue Operations Queue() –Constructs an empty Queue object boolean isEmpty() –Determines whether or not the queue is empty void enqueue( Object o ) –Adds a new element at the rear of the queue Object dequeue() –Removes and returns the element from the front of the queue

Implementation A queue uses a so-called circular array. –Briefly, a circular array is created with an index variable that increments as follows: I = (I+1) % MAX_SIZE Instance variables of a general class –private int front –private int rear –private size –private final int MAX_SIZE –private Object[] q

Implementation (Cont’) public void enqueue( Object o ) { if( size == MAX_SIZE ) throw new NoSuchElementException(); rear = (rear + 1) % MAX_SIZE; q[rear] = o; size++; } Runtime analysis: O(1)

Implementation (Cont’) public Object dequeue() { if( size == 0 ) throw new NoSuchElementException(); Object hold = q[front]; front = (front + 1) % MAX_SIZE; size--; return hold; } Runtime Analysis: O(1)

Queue at Work Breadth-First Search: (pseudo code) bfs (Graph G) { all vertices of G are first painted white the graph root is painted gray and put in a queue while (! Queue.isEmpty() ) { Queue.dequeue( a vertex u ) for all white successors v of u { v is painted gray Queue.enqueue(v); } u is painted black }

Queue at Work (Cont’) Given a graph, as shown on the right

Queue at Work (Cont’) All vertices are colored white

Queue at Work (Cont’)

FINISHED! Time Complexity = O(V+E)

References CS146 Textbook LDS210/queues.htmlhttp://ciips.ee.uwa.edu.au/~morris/Year2/P LDS210/queues.html algorithms/#bfshttp://renaud.waldura.com/portfolio/graph- algorithms/#bfs