Introduction Of Queue. Introduction A queue is a non-primitive linear data structure. It is an homogeneous collection of elements in which new elements.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Introduction to C Programming CE Lecture 12 Circular Queue and Priority Queue Data Structures.
Queues CS-212 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed in their.
Fundamentals of Python: From First Programs Through Data Structures
Lecture - 9 On Queues. Prepared by, Jesmin Akhter, Lecturer, IIT,JU QUEUES A Queue is a linear list of elements in which deletions can take place only.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Queues Objectives: Describe a queue
Data Structures and Algorithms Lecture (Queues) Instructor: Quratulain.
MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
DATA STRUCTURE & ALGORITHMS
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
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.
Queues Chapter 6. Chapter Objectives  To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface for insertion.
1 Queues CPS212 Gordon College. 2 Introduction to Queues A queue is a waiting line – seen in daily life –Real world examples – toll booths, bank, food.
1 Queues and Priority Queues Chapter 8. 2 Introduction to Queues A queue is a waiting line – seen in daily life –Real world examples – toll booths, bank,
Queues Chapter 6. Chapter 6: Queues2 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Chapter 6.6, (event-driven simulation) Queues 1CSCI 3333 Data Structures.
COMP 121 Week 14: Queues. Objectives Learn how to represent a queue Learn how to use the methods in the Queue interface Understand how to implement the.
CHP-4 QUEUE.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
TK1924 Program Design & Problem Solving Session 2011/2012 L6: Queues.
Queue 1 Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
Queues Chapter 6. Chapter 6: Queues Chapter Objectives To learn how to represent a waiting line (queue) and how to use the five methods in the Queue interface:
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
Queue Queue: –Like any other data structure (apart from Array and Linked List), Queue also can be implemented, –Either as an Array or, –As a Linked List.
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.
CHP-4 QUEUE. 1.INTRODUCTION  A queue is a linear list in which elements can be added at one end and elements can be removed only at other end.  That.
UNIVERSAL COLLEGE OF ENGG. AND TECH. 3 RD IT. QUEUE ( data structure)
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
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.
CHP-4 QUEUE Cont…. 7.DEQUE Deque (short form of double-ended queue) is a linear list in which elements can be inserted or deleted at either end but not.
Queues Another Linear ADT Copyright © 2009 Curt Hill.
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
Queues 1. Introduction A sequential collection of data Changes occur at both ends, not just one Queue applications –files waiting to be printed –"jobs"
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
 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.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Review Array Array Elements Accessing array elements
Data Structures Using C++ 2E
Data Structures Using C, 2e
Queues.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Queues.
Program based on queue & their operations for an application
Objectives In this lesson, you will learn to: Define stacks
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Algorithm and Data Structure Part III Dr. Naimah Yaakob
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Queues Mohammad Asad Abbasi Lecture 5
Stacks, Queues, and Deques
DATA STRUCTURE QUEUE.
Data structures.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
[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:

Introduction Of Queue

Introduction A queue is a non-primitive linear data structure. It is an homogeneous collection of elements in which new elements are added at one end called the Rear end and the existing elements are deleted from other end called the Front end. A queue is logically a First In First Out (FIFO) type of list. In our everyday life we come across many situation where we are wait for the desired service, there we have to get into a waiting line for our turn to get serviced.

Introduction This waiting queue can be thought of as a Queue. This Queue means a Line. For example: At the railway reservation booth, we have to get into the reservation queue. Here, the important feature of the queue is when new customers got into the queue from the rear end, whereas the customers who get their sets reserved leave the queue from the front end.

Introduction It means the customers are serviced in the order in which they arrive the service center. This same characteristics apply to our Queue. The next slide figures show queue graphically during insertion and deletion operations.

Introduction The following figures show queue graphically during insertion operation's=Front & R=Rear (a)Empty Queue F=-1 & R= (b) One element inserted in queue F=0 & R= (b) Second element inserted in queue F=0 & R=1 F R F R F R

Introduction The following figures show queue graphically during deletion operation's=Front & R=Rear 1020 (a)Empty Queue F=-1 & R= (b) One element inserted in queue F=1 & R= (b) Second element inserted in queue F=0 & R=1 F R F R F R

Queue Implementation There are two ways to implement a Queue: Static implementation (using array) Dynamic implementation (using Pointer/Linked list)

Static Implementation (using array) If queue is implemented using arrays, we must be sure about the exact number of elements. We want to store in the queue, because we have to declare the size of the array at design time or before the processing starts. In this case, the beginning of the array will become the front for the queue and the last location of the array will act as rear for the queue.

Static Implementation (using array) The following relation gives the total number of elements present in the queue, when implemented using arrays: Total no of elem.=front-rear+1 Also note that if rear<front then there will be no element in the queue or queue is always be empty.

Dynamic implementation (using Pointer/Linked list) Implementing queues using pointers, the main disadvantage is that a node in a linked representation occupies more memory space then a corresponding element in the array representation.

Types of Queue There are many different way to implement a Queue: Simple Queue/Linear Queue Circular Queue Double Ended Queue (Deque) Priority Queue

Simple Queue In the simple queue, the beginning of the array will become the front for the queue and the last location of the array will act as rear for the queue. The following relation gives the total number of elements present in the queue, when implemented using arrays: Total no of elem.=front-rear+1

Simple Queue Also note that if rear<front then there will be no element in the queue or queue is always be empty. Bellow show a figure a empty simple queue Q[5] which can accommodate five elements. Q[0]Q[1]Q[2]Q[3]Q[4] Way of deletionWay of insertion Fig: Simple Queue

Limitation of Simple Queue There are certain problems associated with a simple queue when queue is implemented using array. Consider an example of a simple queue Q[5], which is initially empty. We can only five elements insertion in queue. If we attempt to add more elements, the elements can’t be inserted because in a simple queue rear increment up to size-1.

Limitation of Simple Queue At that time our program will flash the message “Queue is full”. But if the queue is too large of say 5000 elements it will be a tedious job to do and time consuming too. To remove this problem we use circular queue.

Circular Queue A circular queue is one in which the insertion of a new element is done at the very first location of the queue if the last location of the queue is full. In other words if we have a queue Q of say n elements, then after inserting an element last (n-1th) location of the array the next elements will be inserted at the very first location (0) of the array. It is possible to insert new elements, if and only if those location (slots) are empty.

Circular Queue We can say that a circular queue is one in which the first element comes just after the last element. It can be viewed as a mesh or loop of wire, in which the two ends of the wire are connected together. A circular queue overcomes the problem of unutilized space in linear queues implemented as arrays. A circular queue also have a Front and Rear to keep the track of the elements to be deleted and inserted and therefore to maintain the unique characteristic of the queue.

Circular Queue Bellow show a figure a empty circular queue Q[5] which can accommodate five elements. ` Q[0]Q[1] Q[2] Q[3] Q[4] Fig: Circular Queue

Double Ended Queue (Deque) It is also a homogeneous list of elements in which insertion and deletion operations are performed from both the ends. That is, we can insert elements from the rear end or from the front ends. Hence it is called double-ended queue. It is commonly referred as a Deque. There are two types of Deque. These two types are due to the restrictions put to perform either the insertions or deletions only at one end.

Double Ended Queue (Deque) There are: Input-restricted Deque. Output-restricted Deque. Bellow show a figure a empty Deque Q[5] which can accommodate five elements. Q[0]Q[1]Q[2]Q[3]Q[4] deletion insertion Fig: A Deque

Double Ended Queue (Deque) There are: Input-restricted Deque: An input restricted Deque restricts the insertion of the elements at one end only, the deletion of elements can be done at both the end of a queue Q[0]Q[1]Q[2]Q[3]Q[4] deletion insertion Fig: A representation of an input-restricted Deque F R

Double Ended Queue (Deque) There are: Output-restricted Deque: on the contrary, an Output-restricted Deque, restricts the deletion of elements at one end only, and allows insertion to be done at both the ends of a Deque Q[0]Q[1]Q[2]Q[3]Q[4] insertion deletion insertion Fig: A representation of an Output-restricted Deque F R

Double Ended Queue (Deque) The programs for input-restricted Deque and output-restricted Deque would be similar to the previous program of Deque except for a small difference. The program for the input-restricted Deque would not contain the function addqatbeg(). Similarly the program for the output-restricted Deque would not contain the function delatbeg().

Priority Queue A priority queue is a collection of elements where the elements are stored according to their priority levels. The order in which the elements should get added or removed is decided by the priority or the element. Following rules are applied to maintain a priority queue. The element with a higher priority is processes before any element of lower priority.

Priority Queue If there are elements with same priority, then the element added first in the queue would get processed Here, smallest number that is most highest priority and greater number that is less priority. Priority queues are used for implementing job scheduling by the operating system. Where jobs with higher priorities are to be processed first. Another application of priority queue is simulation systems where priority corresponds to event times.

Applications of Queues Round robin technique for processor scheduling is implemented using queues. All types of customer service (like railway ticket reservation) center software’s are designed using queues to store customers information. Printer server routines are designed using queues. A number of users share a printer using printer server the printer server then spools all the jobs from all the users, to the server’s hard disk in a queue. From here jobs are printed one-by-one according to their number in the queue.