DATA STRUCTURE QUEUE.

Slides:



Advertisements
Similar presentations
LINKED LIST, STACKS AND QUEUES Saras M Srivastava, PGT – Comp. Sc. Kendriya Vidyalaya TengaValley.
Advertisements

Data Structure HKOI training /4/2010 So Pak Yeung.
Ceng-112 Data Structures I Chapter 5 Queues.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
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.
MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
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.
CHP-4 QUEUE.
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.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Data Structures Using C++
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.
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.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
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.
Introduction Of Queue. Introduction A queue is a non-primitive linear data structure. It is an homogeneous collection of elements in which new elements.
Computer Engineering Rabie A. Ramadan Lecture 6.
 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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Circular Queues Maitrayee Mukerji. Queues First In – First Out (FIFO) The first element to be inserted is the first one to be retrieved Insertion at one.
1 Data Structures and Algorithms Queue. 2 The Queue ADT Introduction to the Queue data structure Designing a Queue class using dynamic arrays Linked Queues.
STACKS & QUEUES for CLASS XII ( C++).
Review Array Array Elements Accessing array elements
Data Abstraction & Problem Solving with C++
Data Structures Using C, 2e
Queues.
CS505 Data Structures and Algorithms
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Queues Chapter 4.
Using Queues: Coded Messages
COSC160: Data Structures: Lists and Queues
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
CC 215 Data Structures Queue ADT
Program based on queue & their operations for an application
UNIT – I Linked Lists.
Queues Rem Collier Room A1.02
Data Structure Interview Question and Answers
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Chapter 15 Lists Objectives
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Queues Chapter 4.
QUEUE.
CSCE 3110 Data Structures & Algorithm Analysis
Queues Mohammad Asad Abbasi Lecture 5
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Queues.
Stacks, Queues, and Deques
Chapter 15 Lists Objectives
Queues.
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
LINKED LIST.
Queues A first-in, first-out or FIFO data structure.
Queues FIFO Enqueue Dequeue Peek.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Queues Jyh-Shing Roger Jang (張智星)
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
Stacks, Queues, and Deques
Data Structures Using C++ 2E
Queues and Priority Queue Implementations
Queues.
Presentation transcript:

DATA STRUCTURE QUEUE

DEFINITION A Queue is a linear list of elements in which deletion can take place only at one end, called the front, and insertions can take place only at the other end, called the rear.

QUEUE STRUCTURE A Queue is a FIFO structure, since the first element in a queue will be the first element out of the queue. In other words, the order in which elements enter a queue is the order in which they out/leave and physically it can be implemented either as Array or as a Linked List.

QUEUE AS AN ARRAY When a queue is created as an array, its number of elements is declared before processing. The beginning of the array becomes its front end and the end of the array becomes its rear end. Thus, front stores the index of the first element in a

QUEUE AS AN ARRAY queue and rear stores the index of the last element in a queue then Number of elements = front - rear + 1

REPRESENTATION OF AN QUEUE Initially Empty 0 1 2 3 4 Front = NULL Rear = NULL

REPRESENTATION OF AN QUEUE A, B and then C inserted: 0 1 2 3 4 Front = 0 Rear = 2 A B C

REPRESENTATION OF AN QUEUE A deleted: 0 1 2 3 4 Front = 1 Rear = 2 B C

REPRESENTATION OF AN QUEUE D and then E inserted: 0 1 2 3 4 Front = 1 Rear = 4 B C D E

REPRESENTATION OF AN QUEUE B and C deleted: 0 1 2 3 4 Front = 3 Rear = 4 D E

REPRESENTATION OF AN QUEUE D deleted: 0 1 2 3 4 Front = 4 Rear = 4 E

REPRESENTATION OF AN QUEUE K deleted: 0 1 2 3 4 Front = NULL Rear = NULL

INSERTION IN AN ARRAY QUEUE Every insertion increases the value of rear by 1.

ALGORITHM If rear = NULL Then { rear = front = 0 Queue [0] = Item } Else if rear = N-1 Then Print " Queue Full, Overflow"

Else { Queue[rear+1] = Item rear = rear +1 } End. ALGORITHM Else { Queue[rear+1] = Item rear = rear +1 } End.

DELETION IN AN ARRAY QUEUE Whenever an element is deleted from the queue, the value of front is increased by 1.

If front = NULL Then { Print "Queue Empty" } Else ALGORITHM If front = NULL Then { Print "Queue Empty" } Else

Item = Queue[front] If front = rear Then { front = rear = NULL } Else ALGORITHM Item = Queue[front] If front = rear Then { front = rear = NULL } Else

ALGORITHM { front = front +1 } End.

LINKED QUEUE Linked queues are the queues having links among its elements. Two pointers are maintained to store the front position and the rear position.

INSERTION IN A LINKED QUEUE Insertion in a linked queue also takes place only at the rear end. So rear gets modified with every insert.

ALGORITHM /* Allocate space for Item to be inserted */ NEWPTR = new Node NEWPTR ->Info = Item NEWPTR ->Link = NULL

ALGORITHM /* Insert in the Queue*/ If rear = NULL Then { front = NEWPTR rear = NEWPTR

} Else { rear ->Link = NEWPTR rear = NEWPTR END ALGORITHM } Else { rear ->Link = NEWPTR rear = NEWPTR END

DELETION IN A LINKED QUEUE Deletions in a linked queue take place from the front end. Therefore the front gets modified with every delete.

If rear = NULL Then Print "Queue Empty" Else { Item = front ->Info ALGORITHM If rear = NULL Then Print "Queue Empty" Else { Item = front ->Info

If front = rear Then { front = rear = NULL } Else ALGORITHM If front = rear Then { front = rear = NULL } Else

front = front ->Link } END ALGORITHM front = front ->Link } END

VARIATIONS IN QUEUES Two popular variations in queues are - 1. Circular Queues 2. Dequeues (Double-Ended Queues)

CIRCULAR QUEUE Circular Queues are the queues implemented in circular form rather than a straight line. Circular queues overcome the problem of unutilized space in linear queues implemented as arrays.

REPRESENTATION OF AN CIRCULAR QUEUE Initially Empty 0 1 2 3 4 Front = NULL Rear = NULL

REPRESENTATION OF AN CIRCULAR QUEUE A, B and then C inserted: 0 1 2 3 4 Front = 0 Rear = 2 A B C

REPRESENTATION OF AN CIRCULAR QUEUE A deleted: 0 1 2 3 4 Front = 1 Rear = 2 B C

REPRESENTATION OF AN CIRCULAR QUEUE D and then E inserted: 0 1 2 3 4 Front = 1 Rear = 4 B C D E

REPRESENTATION OF AN CIRCULAR QUEUE B and C deleted: 0 1 2 3 4 Front = 3 Rear = 4 D E

REPRESENTATION OF AN CIRCULAR QUEUE K inserted: 0 1 2 3 4 Front = 3 Rear = 0 K D E

REPRESENTATION OF AN CIRCULAR QUEUE D deleted: 0 1 2 3 4 Front = 4 Rear = 0 K E

REPRESENTATION OF AN CIRCULAR QUEUE G inserted: 0 1 2 3 4 Front = 4 Rear = 1 K G E

DEQUE (DOUBLE-ENDED QUEUES) Deques are the queues in which elements can be added or removed at either end but not in the middle. There are two variation of a deque – 1. Input Restricted Deque 2. Output Restricted Deque

INPUT RESTRICTED DEQUE It is a deque which allows insertions at only one end but allows deletions at both ends of the list

OUTPUT RESTRICTED DEQUE It is a deque which allows deletions at only one end but allows insertions at both ends of the list

ALOK GUPTA PGT (COMPUTER SCIENCE) KV, SECTOR VIII R K PURAM, NEW DELHI THANK YOU ALOK GUPTA PGT (COMPUTER SCIENCE) KV, SECTOR VIII R K PURAM, NEW DELHI