Queues Tonga Institute of Higher Education. Definitions Queue - A data structure that stores a number of items. The first item entered into a queue is.

Slides:



Advertisements
Similar presentations
QUEUE Education is the best friend. An educated person is respected everywhere. Education beats the beauty and the youth. Chanakya.
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.
Queues.
Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
Lec 7 Sept 17 Finish discussion of stack infix to postfix conversion Queue queue ADT implementation of insert, delete etc. an application of queue.
Stacks and Queues. 2 Stack and Queue ADT’s You should understand How are they different philosophically from arrays What are they used for How do you.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Data Structures and Algorithms Lecture (Queues) Instructor: Quratulain.
Data Structure Dr. Mohamed Khafagy.
COP3538 – Data Structures Using OOP Chapter 4 – Stacks and Queues.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 4.
 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.
CHAPTER 5 PRIORITY QUEUES (HEAPS) §1 ADT Model Objects: A finite ordered list with zero or more elements. Operations:  PriorityQueue Initialize( int.
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.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Cmpt-225 Queues. A queue is a data structure that only allows items to be inserted at the end and removed from the front Queues are FIFO (First In First.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
Stack: Linked List Implementation Push and pop at the head of the list New nodes should be inserted at the front of the list, so that they become the top.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Lecture 11 Sept 26, 2011 Goals convert from infix to postfix.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Programming Logic and Design Fourth Edition, Comprehensive
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.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 8 Ming Li Department of.
Chapter 24 Dispensers and dictionaries. This chapter discusses n Dictionaries n Dispensers u stacks u queues u priority queues.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Introduction to Data Structures. Data Structures A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
1 HEAPS & PRIORITY QUEUES Array and Tree implementations.
Introduction to Data Structures. About the document. The document is prepared by Prof. Shannon Bradshaw at Drew University. The key concepts in data structure.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Stacks and Queues Introduction to Computing Science and Programming I.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Arrays Tonga Institute of Higher Education. Introduction An array is a data structure Definitions  Cell/Element – A box in which you can enter a piece.
Queue 1 Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
1 Heaps and Priority Queues Starring: Min Heap Co-Starring: Max Heap.
Linked Lists Tonga Institute of Higher Education.
Sorts Tonga Institute of Higher Education. Introduction - 1 Sorting – The act of ordering data Often, we need to order data.  Example: Order a list of.
COSC2007 Data Structures II Chapter 12 Tables & Priority Queues III.
Arrays and Collections Tonga Institute of Higher Education.
18-1 Queues Data Structures and Design with Java and JUnit © Rick Mercer.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
CHAPTER 5 PRIORITY QUEUES (HEAPS) §1 ADT Model Objects: A finite ordered list with zero or more elements. Operations:  PriorityQueue Initialize( int.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Stack and Queues Part 2. Priority Queues Priority Queues (cont’) A priority queue is a more specialized data structure than a stack or a queue. However,
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.
Queues Another Linear ADT Copyright © 2009 Curt Hill.
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
INTRODUCTION TO DATA STRUCTURES 1. DATA STRUCTURES A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Queues.
Chapter 12 – Data Structures
COSC160: Data Structures: Lists and Queues
Priority Queues and Heaps
Tonga Institute of Higher Education
CSC 143 Queues [Chapter 7].
Tonga Institute of Higher Education
Priority Queues & Heaps
Presentation transcript:

Queues Tonga Institute of Higher Education

Definitions Queue - A data structure that stores a number of items. The first item entered into a queue is the first item to be removed Peek – The act of viewing the value of the item at the front of the queue. Note: You cannot see the values for items behind the front item FIFO – First in First out – Sometimes used to describe a queue

Examples of Queues Waiting to checkout at a grocery store The queue for our laser printer The keyboard remembers the letters you type so even if the computer is busy, they still stay in order when the computer is able to print them.

Queue Implemented as an Array 1 st in line2 nd in line3 rd in line We can implement a queue using an array Each cell of the array represents a thing in the queue The front of queue is on the left The back of the queue is on the right

Queue Considerations Queue Size – Can be set when the queue is created Errors:  We try to add an item when the queue is full  We try to remove an item when the queue is empty

Circular Queue If you use an array, your queue will reach the end of the array and you’ll won’t be able to add more items even though there are empty cells in your array By allowing the data to wrap around the array, we can void this problem

Demonstration Queue Applet

Demonstration Queue Code

Efficiency of Queues Items can be added and removed in constant O(1) time This time is not dependent on the number of items in the queue so it is very fast No comparisons or moves are necessary

Example of Priority Queues You get a bunch of letters and order them:  Letters with high priority (bills) get moved to the front of the queue  Letters with medium priority (letter from grandmother) get moved to the middle of the queue  Letters with low priority (advertisements) get moved to the bottom of the queue Your computer multitasks. (Does many things at the same time)  Important programs are put in the front of the queue to be done first.  Non-important programs are put to the back of the queue to be done later.

Priority Queues Works like an ordinary queue However, the order of how things are removed depend on a priority key Ascending Priority Queue – The item with the smallest key has the highest priority Descending Priority Queue – The item with the largest key has the highest priority

Demonstration Priority Queue Applet

Demonstration PriorityQueue Code

Efficiency of Priority Queues Adding items  This is slow because the proper in-order position must be found and created  Shifting and comparisons are needed  Runs in O(N) time Deleting items  This is fast because the item to be deleted is always at the top of the array  No shifting or comparisons are needed  Runs in O(1) time