Queues Model Operations Pointer Implementations Array Implementation

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Queues and Linked Lists
1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
§3 The Stack ADT 1. ADT A stack is a Last-In-First-Out (LIFO) list, that is, an ordered list in which insertions and deletions are.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Queue & List Data Structures & Algorithm Abstract Data Types (ADTs) ADT is a mathematically specified entity that defines a set of its instances,
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.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Lists CSE1303 Part A Data Structures and Algorithms.
Tutorial 5 Linked List Variations, Stack, & Queue.
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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.
UNIVERSAL COLLEGE OF ENGG. AND TECH. 3 RD IT. QUEUE ( data structure)
Linear Data Structures
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Elementary Data Structures
Review Array Array Elements Accessing array elements
Elementary data structures
CS505 Data Structures and Algorithms
Week 4 - Monday CS221.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
CC 215 Data Structures Queue ADT
Program based on queue & their operations for an application
Linked List Stacks, Linked List Queues, Dequeues
Chapter 15 Lists Objectives
CS 1114: Implementing Search
Sequences 8/1/2018 4:38 AM Linked Lists Linked Lists.
Stacks and Queues.
Queues Queues Queues.
Single Pointer Implemention
Data Structures and Database Applications Queues in C#
CMSC 341 Lecture 5 Stacks, Queues
Principles of Computing – UFCFA3-30-1
Stacks, Queues, and Deques
Circular queue.
Stacks, Queues, and Deques
Data Structures – Stacks and Queus
אחסון (אירגון) מידע DATA DATA DATA Link Link Link … …
CSC 143 Queues [Chapter 7].
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
Stacks and Queues CSE 373 Data Structures.
Queues A first-in, first-out or FIFO data structure.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Data Structures and Algorithms for Information Processing
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Stacks and Queues CSE 373 Data Structures.
CSE 373 Data Structures Lecture 6
Stacks and Queues CSE 373 Data Structures.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
CS210- Lecture 6 Jun 13, 2005 Announcements
CSE 373 Data Structures Lecture 6
Stacks, Queues, and Deques
Queues and Priority Queue Implementations
Getting queues right … finally (?)
Queues Dr. Anwar Ghani Lecture 06: Queue Data Structures
Lecture 9: Stack and Queue
Presentation transcript:

Queues Model Operations Pointer Implementations Array Implementation Stacks and Recursive Procedures 4/21/2019 CS 303 – Queues Lecture 6

ADT Queue - Model Specialization of List FIFO: First In, First Out Insert at End Delete at Front 4/21/2019 CS 303 – Queues Lecture 6

Queue - Operations MakeNull(Q) // MakeNull(L) T/F = Empty(Q) // First(L) == End(L) Enqueue(Q,x) // Insert(L,End(L),x) x = Front(Q) // Retrieve(L,First(L)) Dequeue(Q) // Delete(L,First(L)) [Variation: x = Dequeue(Q) Exercise: work out details] x: ElementType S: StackType L: ListType Any List Implementation will do, but can we do better? 4/21/2019 CS 303 – Queues Lecture 6

Pointer Implementations – First Attempts Doubly Linked List? [Overkill] Q a1 a2 an Singly Linked List? [no Header, but still pointer overhead] Dequeue is EASY, but Enqueue is HARD Q a1 a2 a3 ... an 4/21/2019 CS 303 – Queues Lecture 6

A better Pointer Implementation Q a1 a2 a3 ... an Enqueue and Dequeue are both EASY 4/21/2019 CS 303 – Queues Lecture 6

Array Implementation Circular Array, with zero-based indexing i i+1 i+n-1 MaxLength-1 a1 a2 an Front Rear Circular Array, with zero-based indexing Full/Empty conditions are tricky! Leave empty buffer region to avoid bugs and simplify code. 4/21/2019 CS 303 – Queues Lecture 6

Stacks and Recursive Procedures Recursion is implemented (by the System) by Pushing state onto a Stack Even when this is provided automatically, you must Analyze as if the stack were explicit. Sometimes it is useful to manage the stack explicitly Usually better to write recursive routines and let the System do it Manual elimination of tail recursion considered harmful! All bets are off in primitive environments. 4/21/2019 CS 303 – Queues Lecture 6