Algorithm and Data Structure Part III Dr. Naimah Yaakob

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
Ceng-112 Data Structures I Chapter 5 Queues.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Queues1 Part-B2 Queues. Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out scheme.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
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.
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.
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.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Circular queue. Array-based Queue Use an array of size N in a circular fashion Three variables keep track of the front, rear, and size f index of the.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
CHP-4 QUEUE.
Queue 1 Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
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.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
CE 221 Data Structures and Algorithms
Queue. Avoid confusion Britain Italy 6 Applications of Queues Direct applications –Waiting lists, bureaucracy –Access to shared resources (e.g.,
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
Queue. The Queue ADT Insertions and deletions follow the first-in first-out scheme Insertions are at the rear of the queue and removals are at the front.
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.
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.
 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.
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.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Queues1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
Review Array Array Elements Accessing array elements
Data Structures Using C, 2e
Queues.
UNIT II Queue.
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Queues.
Program based on queue & their operations for an application
Algorithm and Data Structure Part II Dr. Naimah Yaakob
Objectives In this lesson, you will learn to: Define stacks
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Queues Queues Queues.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Priority Queue.
CSCE 3110 Data Structures & Algorithm Analysis
Principles of Computing – UFCFA3-30-1
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues 11/9/2018 6:32 PM Queues.
Queues 11/16/2018 4:18 AM Queues 11/16/2018 4:18 AM Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Circular queue.
Queues.
DATA STRUCTURE QUEUE.
Queue.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Revised based on textbook author’s notes.
CSC 143 Queues [Chapter 7].
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
Queues 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Queues Jyh-Shing Roger Jang (張智星)
Copyright © Aiman Hanna All rights reserved
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
Uniprocessor scheduling
CE 221 Data Structures and Algorithms
CSCS-200 Data Structure and Algorithms
Presentation transcript:

Algorithm and Data Structure Part III Dr. Naimah Yaakob EKT 334 Algorithm and Data Structure Chapter 5 – Queues Part III Dr. Naimah Yaakob

Deques A deque has two variants, viz., input restricted deque and output restricted deque. An input restricted deque is one where insertions are allowed at one end only while deletions are allowed at both ends. On the other hand, an output restricted deque allows insertions at both ends of the deque but permits deletions only at one end. A deque is commonly implemented as a circular array with two variables LEFT and RIGHT taking care of the active ends of the deque

Example 5.4: Let DEQ[1:6] be a deque implemented as a circular array. The contents of DEQ and that of LEFT and RIGHT are as given below: Should be here

It is easy to observe that for insertion at the left end, LEFT is decremented by 1 (mod n) and for insertions at the right end, RIGHT is incremented by 1 (mod n). For deletions at the left end, LEFT is incremented by 1 (mod n) and for deletions at the right end, RIGHT is decremented by 1 (mod n) where n is the capacity of the queue. Again, before performing a deletion, if LEFT=RIGHT, then it implies that there is only one element and in such a case after deletion set LEFT=RIGHT=NIL to indicate that the deque is empty

Applications : Linear Queue Application Of A Linear Queue : A Time Sharing System A CPU (processor) endowed with memory resources, is to be shared by n number of computer users. The sharing of the processor and memory resources is done by allotting a definite time slice of the processor’s attention on the users and in a round- robin fashion (time quantum). In a system such as this the users are unaware of the presence of other users and are led to believe that their job receives the undivided attention of the CPU. However, to keep track of the jobs initiated by the users, the processor relies on a queue data structure recording the active user- ids.

Example

Example of Linear Queue Arrival Time A B 1 C 2 **Any 2 sequential job has 5µs delay

How the CPU handles the queue?? As soon as the request is made by a user, the user ID is inserted into a queue A job that is to processed next would be the one at the head of the queue A job remains at the head of the queue until it completes its execution. Once completed, its user ID is deleted from the queue A snapshot of the queue data structure at t=5,10 and 14 is as follows B

Applications : Priority Queue Assume different kinds of job request: 1. Real time (highest) 2. Online (medium) 3. Batch job (lowest) ** the job scheduler needs to maintain one-queue for Real-time (R), one for Online job (O) and one for batch job (B) **CPU can only executes the job in O when the job in queue R is empty. Queue B can only be executed when queue R and O are emptied.

Example of Priority Queue Arrival Time A B 1 C 2 **Any 2 sequential job has 5µs delay

ADT for Queues Data objects: A finite set of elements of the same type Operations: Create an empty queue and initialize front and rear variables of the queue CREATE ( QUEUE, FRONT, REAR) Check if queue QUEUE is empty CHK_QUEUE_EMPTY (QUEUE ) (Boolean function) Check if queue QUEUE is full CHK_QUEUE_FULL (QUEUE) (Boolean function) Insert ITEM into rear of queue QUEUE ENQUEUE (QUEUE, ITEM) Delete element from the front of queue QUEUE and output the element deleted in ITEM DEQUEUE (QUEUE , ITEM)