Queues. Lesson 4. CS 32: Data Structures Dept. of Computer Science

Similar documents
1 P age DS & OOPS / UNIT II

Queues COL 106. Slides by Amit Kumar, Shweta Agrawal

Topic 2. Collections

Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras

STACKS AND QUEUES. Problem Solving with Computers-II

How to Win Coding Competitions: Secrets of Champions. Week 2: Computational complexity. Linear data structures Lecture 5: Stack. Queue.

CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh University of Toronto Scarborough

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

CH 6 : VECTORS, LISTS AND SEQUENCES

Another common linear data structure similar to. new items enter at the back, or rear, of the queue. Queue is an ADT with following properties

CS301 - Data Structures Glossary By

Ashish Gupta, Data JUET, Guna

DATA STRUCTURE UNIT I

Objectives. Upon completion you will be able to:

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1

.:: UNIT 4 ::. STACK AND QUEUE

csci 210: Data Structures Stacks and Queues

Queues. ADT description Implementations. October 03, 2017 Cinda Heeren / Geoffrey Tien 1

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II


CH 6 : VECTORS, LISTS AND SEQUENCES

CSCA48 Winter 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh, Nick Cheng University of Toronto Scarborough

CH 6. VECTORS, LISTS, AND SEQUENCES

COSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor

CMSC Introduction to Algorithms Spring 2012 Lecture 7

Your Topic Goes Here Queue

Data Structure. Recitation VII

Queues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1

ITI Introduction to Computing II

12 Abstract Data Types

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Lists, Stacks, and Queues. (Lists, Stacks, and Queues ) Data Structures and Programming Spring / 50

Stack and Queue. Stack:

Queue ADT. January 31, 2018 Cinda Heeren / Geoffrey Tien 1

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

PA3 Design Specification

Programming Abstractions

Chapter 18: Stacks And Queues

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

CSE 373 SEPTEMBER 29 STACKS AND QUEUES

1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University

Subject : Computer Science. Paper: Data Structures. Module: Priority Queue and Applications. Module No: CS/DS/14

Week 6. Data structures

Information Science 2

Introduction to Data Structures and Algorithms

Chapter 18: Stacks And Queues

HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS

Lecture Data Structure Stack

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

Chapter 18: Stacks And Queues. Pearson Education, Inc. Publishing as Pearson Addison-Wesley

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

Cpt S 122 Data Structures. Data Structures

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES

DEEPIKA KAMBOJ UNIT 2. What is Stack?

Postfix (and prefix) notation

Fundamentals of Data Structure

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

DS L9: Queues

Data Structures and Algorithms

Queues. Queue ADT Queue Implementation Priority Queues

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

CS 310 Advanced Data Structures and Algorithms

Name: 1 stack<int> s; 2 s.push(9) 3 s.push(5) 4 s.push(10) 5 s.push(1) 6 s.pop() 7 s.pop() 8 s.push(0) 9 s.pop() 10 s.pop() 11 s.

Linked List. April 2, 2007 Programming and Data Structure 1

Data Structures Lecture 5

CSC148 Week 2. Larry Zhang

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Data structure and algorithm in Python

Algorithms and Data Structures

CS8391-DATA STRUCTURES

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

LIFO : Last In First Out

CS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.

Department of Computer Science and Technology

PHYC 500: Introduction to LabView. Exercise 15 (v 1.2) Producer Consumer Event Structure. M.P. Hasselbeck, University of New Mexico

How can we improve this? Queues 6. Topological ordering: given a sequence of. should occur prior to b, provide a schedule. Queues 5.

CSC148H Week 3. Sadia Sharmin. May 24, /20

Definition of a Heap. Heaps. Priority Queues. Example. Implementation using a heap. Heap ADT

Motivation for Queues

[ DATA STRUCTURES ] Fig. (1) : A Tree

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

CSE 332: Data Structures & Parallelism Lecture 3: Priority Queues. Ruth Anderson Winter 2019

PRACTICAL LIST FOR EVEN SEMESTERS (PGDCA/MCA/MSC (CS))

CS 8391 DATA STRUCTURES

Final Exam Data Structure course. No. of Branches (5)

CSE 373 Data Structures and Algorithms. Lecture 2: Queues

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue

Problem 1: Building and testing your own linked indexed list

Module 2: Priority Queues

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

data structures and algorithms lecture 6

CSE 230 Intermediate Programming in C and C++

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

Transcription:

Queues Lesson 4

Outline What is a queue? Straight queue Circular Queue Sequential Implementation Linked Implementation Application: Topological sort Deques Final Notes

Outline What is a queue? Straight queue Circular Queue Sequential Implementation Linked Implementation Application: Topological sort Deques Final Notes r

What is a queue? First in, first out ADT Operations ( stacks Auxiliary (same as Enqueue Dequeue

Straight queue Straight queue Circular queue

Outline What is a queue? Straight queue Circular Queue Sequential Implementation Linked Implementation Application: Topological sort Deques Final Notes

Enqueue Straight queue

Dequeue Straight queue

Enqueue Circular queue Dequeue

Outline What is a queue? Straight queue Circular Queue Sequential Implementation Linked Implementation Application: Topological sort Deques Final Notes

Enqueue Straight queue

Dequeue Straight queue

Outline What is a queue? Straight queue Circular Queue Sequential Implementation Linked Implementation Application: Topological sort Deques Final Notes

Topological sort Arrange objects in the sequence such that no objects appear before its (direct) predecessors Notion of (partial) ordering of a set e.g. integer numbers arranged according to increasing magnitude ( sorted (not 2 1, 2, 6, 7, 5, 4, 3, ( sorted ) 1, 2, 2, 3, 4, 5, 6, 7

Topological sort Practical application: creating study plan for a program of study

Topological sort Really a problem involving graphs, but nonetheless uses a queue in one of the implementations of topological sort Idea for topological sort Determine partial ordering of the elements by creating predecessor-successor pairs Keep count of the number of direct predecessors and tag successors for all objects Can use linked lists here Initialize a queue and dequeue it to produce output

Involving queues in TS Makes use of a linked queue Initially, all elements are objects with no direct predecessors A count of all the predecessors of the objects is kept Each time count of direct predecessors drops to zero, object is inserted into queue ready for output A linked list of all the direct successors of an object is kept Optimization: overstore queue in count array by reusing the count field as a link field when the count drops to zero

TS: An Example

TS: An Example

Involving queues in TS Initialize the queue Scan the table for all inputs. If an object is found which has no direct predecessors, then enqueue it Use the count field as a link field (optimization) Initially of course, front points to nothing, and once an initial object is enqueued, that object becomes front and rear altogether

Involving queues in TS Dequeueing the output Output front of the queue and all that link to it (i.e. the successors). For each of the successors that is output, decrement the count of its direct successors If the count of a direct successor reaches zero, enqueue it Dequeue the front of the queue and proceed processing of the next item in line Repeat process until queue is empty

Outline What is a queue? Straight queue Circular Queue Sequential Implementation Linked Implementation Application: Topological sort Deques Final Notes

Deques Deque = Double Ended Queue Apart from the usual input parameters in enqueue and dequeue, one must also specify where insertion or deletion will be done. Also, instead of front and rear, ends of a deque are labeled l(eft) and r(ight)

Deques Sequential Implementation Initializing a sequential deque WHY?!

Deques Sequential Implementation

Circular Deques Initialization (HOW?!!)

Circular Deques

Deques Linked Implementation

Deques Linked Implementation

Outline What is a queue? Straight queue Circular Queue Sequential Implementation Linked Implementation Application: Topological sort Deques Final Notes

Final Notes Queues are usually implemented in problems that resemble first-come, first-served policies, as well as traversal algorithms Issue in TS: What if there are loops, i.e. A < B < C < A? Deques are not commonly used in practice; nonetheless, implementing the deque ADT is an interesting academic exercise. But there are interesting practical applications, e.g. processor job scheduling

Thank you for your attention. Questions...