Queues Linear list. One end is called front. Other end is called rear.

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

Data Structures and Algorithms (60-254)
Queues Linear list. One end is called front. Other end is called rear. Additions are done at the rear only. Removals are made from the front only.
Queues CSE, POSTECH 2 2 Queues Like a stack, special kind of linear list One end is called front Other end is called rear Additions (insertions or enqueue)
Queues Linear list. One end is called front. Other end is called rear. Additions are done at the rear only. Removals are made from the front only.
Queue Chapter 9 Stacks Last in first out (LIFO)Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top.
Chapter 3 1. Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable that can.
CS Data Structures II Review COSC 2006 April 14, 2017
Stacks  Standard operations: IsEmpty … return true iff stack is empty IsFull … return true iff stack has no remaining capacity Top … return top element.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
Breadth-First Search David Johnson. Today Look at one version of Breadth-first search on a grid Develop Matlab version of BFS.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Unit : Overview of Queues.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Graphs. Made up of vertices and arcs Digraph (directed graph) –All arcs have arrows that give direction –You can only traverse the graph in the direction.
Stacks Chapter 8. Objectives In this chapter, you will: Learn about stacks Examine various stack operations Learn how to implement a stack as an array.
Stacks And Queues Chapter 18.
Queue 09/10/081. Queue (Linear Queue) It is a linear data structure consisting of list of items. In queue, data elements are added at one end, called.
Applications of Stacks and Queues Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Queues Linear list. One end is called front. Other end is called rear. Additions are done at the rear only. Removals are made from the front only. 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.
UNIVERSAL COLLEGE OF ENGG. AND TECH. 3 RD IT. QUEUE ( data structure)
1 Chapter 6 Queues. 2 Topics FIFO (first0in-first0out) structure Implementations: formula-based and linked classes Applications: –railroad-switching problem.
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.
Computer Engineering Rabie A. Ramadan Lecture 6.
Midterm Review Linear list Stack queue. What is a data structure What is an abstract data type.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
STACKS & QUEUES for CLASS XII ( C++).
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Review Array Array Elements Accessing array elements
Data Structures Using C, 2e
Queues.
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
A vertex u is reachable from vertex v iff there is a path from v to u.
Stacks Linear list. One end is called top. Other end is called bottom.
Chapter 15 Lists Objectives
Stacks.
Objectives In this lesson, you will learn to: Define stacks
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
Stack and Queue.
Stacks and Queues.
CMSC 341 Lecture 5 Stacks, Queues
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Stacks and Queues.
Queues Linear list. One end is called front. Other end is called rear.
Lectures on Graph Algorithms: searching, testing and sorting
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Stacks and Queues CLRS, Section 10.1.
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.
پشته ها و صف ها.
Stacks and Queues 1.
Stacks and Queues.
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
CE 221 Data Structures and Algorithms
A vertex u is reachable from vertex v iff there is a path from v to u.
Stacks, Queues, and Deques
Stacks and Queues.
Chapter 7 © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 4 Stacks and Queues
Data Structures & Programming
Presentation transcript:

Queues Linear list. One end is called front. Other end is called rear. Additions are done at the rear only. Removals are made from the front only. By comparison, in a stack adds and removes are to/from the same end of he list.

Bus Stop Queue Bus Stop front rear rear rear rear rear

Bus Stop Queue Bus Stop front rear rear rear

Bus Stop Queue Bus Stop front rear rear

Bus Stop Queue Bus Stop front rear rear This is FIFO queue. Some real life queues are not FIFO. Removal from a queue may be done by priority rather than by arrival time order. For example, loading into a plane– first class, frequent fliers, by rows from back of plane rather than by order in which you arrive at the departure gate.

Revisit Of Stack Applications Applications in which the stack cannot be replaced with a queue. Parentheses matching. Towers of Hanoi. Switchbox routing. Method invocation and return. Try-catch-throw implementation. Application in which the stack may be replaced with a queue. Rat in a maze. Results in finding shortest path to exit.

Wire Routing Represent as a grid in which components and already placed wires are denoted by blocked grid positions.

Lee’s Wire Router Label all reachable squares 1 unit from start. start pin end pin Could use rat in a maze animation from Web site instead. Blue squares are blocked squares. Orange squares are available to route a wire. A queue of reachable squares is used. The queue is initially empty, and the start pin square/cell is the examine cell. This cell has a distance value of 0. Unreached unblocked squares adjacent to the examine cell are marked with their distance (this is 1 more than the distance value of the examine cell) and added to the queue. Then a cell is removed from the queue and made the new examine cell. This process is repeated until the end pin is reached or the queue becomes empty. Cells become examine cells in order of their distance from the start pin. Label all reachable squares 1 unit from start.

Lee’s Wire Router start pin end pin 1 1 Label all reachable unlabeled squares 2 units from start.

Lee’s Wire Router start pin 2 2 end pin 1 1 2 2 2 Label all reachable unlabeled squares 3 units from start.

Lee’s Wire Router start pin 3 3 2 2 end pin 1 1 2 2 2 3 3 Label all reachable unlabeled squares 4 units from start.

Lee’s Wire Router start pin 4 3 3 2 2 end pin 1 1 2 2 2 3 4 3 4 4 4 Label all reachable unlabeled squares 5 units from start.

Lee’s Wire Router 5 start pin 4 5 3 3 2 2 end pin 1 1 2 2 2 3 4 3 4 5 4 4 5 5 5 Label all reachable unlabeled squares 6 units from start.

Lee’s Wire Router End pin reached. Traceback. 6 5 6 start pin 4 5 3 3 2 2 end pin 1 1 2 2 2 6 3 4 3 4 5 6 4 4 5 6 5 6 5 6 6 End pin reached. Traceback.

Lee’s Wire Router End pin reached. Traceback. 6 5 6 start pin 4 5 3 3 2 2 end pin 1 1 1 2 2 2 2 6 3 4 3 3 4 4 5 5 6 4 4 5 6 5 6 5 6 6 End pin reached. Traceback.

Queue Operations IsEmpty … return true iff queue is empty Front … return front element of queue Rear … return rear element of queue Push … add an element at the rear of the queue Pop … delete the front element of the queue

Queue in an Array Use a 1D array to represent a queue. Suppose queue elements are stored with the front element in queue[0], the next in queue[1], and so on.

Derive From arrayList Pop() => delete queue[0] 1 2 3 4 5 6 a b c d e Pop() => delete queue[0] O(queue size) time Push(x) => if there is capacity, add at right end O(1) time

O(1) Pop and Push to perform each opertion in O(1) time (excluding array doubling), we use a circular representation.