Data Structures and Analysis (COMP 410)

Slides:



Advertisements
Similar presentations
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 be instantiated.
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.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
A queue is an ADT which allows data values to be accessed only one at a time and only the first inserted. The rule imposed on a queue is: First In First.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
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.
Chapter 13 Queues and Priority Queues CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Data Structures: Lists i206 Fall 2010 John Chuang Some slides adapted from Glenn Brookshear, Brian Hayes, or Marti Hearst.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
Stacks, Queues & Deques CSC212.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
CSC212 Data Structure - Section FG Lecture 12 Stacks and Queues Instructor: Zhigang Zhu Department of Computer Science City College of New York.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Stacks and Queues Introduction to Computing Science and Programming I.
David Stotts Computer Science Department UNC Chapel Hill.
TECH Computer Science Data Abstraction and Basic Data Structures Improving efficiency by building better  Data Structure Object IN  Abstract Data Type.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
David Stotts Computer Science Department UNC Chapel Hill.
1 Heaps and Priority Queues Starring: Min Heap Co-Starring: Max Heap.
CMSC 202 Stacks and Queues. What’s a Queue? A queue is a linear collection of homogeneous data in which items added to the queue must be placed at the.
David Stotts Computer Science Department UNC Chapel Hill.
Data Structures Using C++
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
1 Heaps and Priority Queues v2 Starring: Min Heap Co-Starring: Max Heap.
David Stotts Computer Science Department UNC Chapel Hill.
1 Stacks & Queues CSC Stacks & Queues Stack: Last In First Out (LIFO). –Used in procedure calls, to compute arithmetic expressions etc. Queue: First.
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Topic 2 Collections. 2-2 Objectives Define the concepts and terminology related to collections Discuss the abstract design of collections.
David Stotts Computer Science Department UNC Chapel Hill.
COMP 103 Maps and Queues. RECAP  Iterators (for-each loop)  Bag, Sets, and Stacks - a class, not interface TODAY  Maps and Queues 2 RECAP-TODAY QUICK.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
Linked Data Structures
CSE373: Data Structures & Algorithms Priority Queues
Stack ADT (Abstract Data Type) N …
CSE373: Data Structures & Algorithms
Queues Chapter 4.
Chapter 11 Heap.
Programming Abstractions
Data Structures and Analysis (COMP 410)
Algorithm and Data Structure Part III Dr. Naimah Yaakob
Data Structures and Analysis (COMP 410)
Priority Queue.
Chapter 13 Queues and Priority Queues
Introduction to Data Structure
Queues, Deques and Priority Queues
Data Structures and Analysis (COMP 410)
Queues, Deques and Priority Queues
Data Structures and Analysis (COMP 410)
Data Structures and Analysis (COMP 410)
COMPUTER 2430 Object Oriented Programming and Data Structures I
CSE332: Data Abstractions Lecture 4: Priority Queues
Programming Abstractions
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Priority Queues - Harvey B. Mackay
Data Structures and Analysis (COMP 410)
Data Structures and Analysis (COMP 410)
Data Structures and Analysis (COMP 410)
Stacks and Queues.
Abstract Data Type (ADT)
CE 221 Data Structures and Algorithms
[Most of the details about queues are left for to read about and work out in Lab 6.] Def. As a data structure, a queue is an ordered collection of data.
Presentation transcript:

Data Structures and Analysis (COMP 410) David Stotts Computer Science Department UNC Chapel Hill

Priority Queue

Find the highest priority Consider an emergency room at a hospital Patients arrive at various time with various injuries and maladies Triage is done to determine level of emergency and priority Doctors finish with one patient, take the next not in FIFO order but in highest priority order

Find the highest priority Consider an operating system Processes are created (by user, by system) each with a priority, and go into a “pool” Higher priority processes get more time, or first use of processor When one process finishes (or ends time slice) the next process to run is the one with highest priority Must select this from the pool somehow, might have 1000’s of processes

Priority Queue at the abstract level Let’s work with elements composed of two pieces: the data value (injury, process, document, etc.) a priority (something like int that can be ordered) 2.4 9 9.5 8 6.4 1 4.7 3 7.3 5 8.0 7

Find the highest priority From this blob get the element with highest priority Now get the next element with highest priority 6.4 1 9.5 8 2.4 9 Add another element 3.1 2 Get next highest priority element 4.7 3 7.3 5 8.0 7

PrQUE ADT Priority Queue is an abstract type like Queue, Stack are abstract Functional signature ( like used for axioms ) enq : PrQUE x elt x priority  PrQUE deq : PrQUE  PrQUE front : PrQUE  elt size, empty, etc. The “enq” puts an item with its priority into the PrQUE The “front” gives the item with highest priority The “deq” removes the highest priority item from the PrQUE PrQUE is not FIFO, not LIFO, order is based on priorities

PrQUE ADT OO signature enq : Elt x Priority  ( or Boolean or something else ) deq :  ( or Boolean etc. ) front :  Elt frontPri  Priority ( maybe int ) size, empty, etc. The “enq” puts an item with its priority into the PrQUE The “front” gives the item with highest priority The “deq” removes the highest priority item from the PrQUE PrQUE is not FIFO, not LIFO, order is based on priorities

Implementation? Discuss in Poll Everywhere

Beyond this is just templates END Beyond this is just templates