How can we improve this? Queues 6. Topological ordering: given a sequence of. should occur prior to b, provide a schedule. Queues 5.
|
|
- Gladys Carson
- 6 years ago
- Views:
Transcription
1 Queues 1 Queues A Queue is a sequential organization of items in which the first element entered is the first removed. They are often referred to as FIFO, which stands for first in first out. Examples: standing in a line, printer queue. The basic operations are: insert(x) (a.k.a. enqueue(x)) places x at the beginning (head) of the queue. remove() (a.k.a. dequeue()) returns and deletes the item at the end (tail) of the queue. Example: Operation Queue Return CreateQueue () insert(7) (7) insert(8) (7,8) insert(5) (7,8,5) remove() (8,5) 7 remove() (5) 8 Queues 4 Queues: A Better Implementation Keep track of both the head and the tail. To remove, increment head. a b c d head = 0 tail = 4 remove a b c d head = 0 tail = 4 update head b c d head = 1 tail = 4 There is still a problem. What is it, and how can we fix it? Queues 2 Queue Applications Operating systems: Queue of jobs or processes ready to run (waiting for CPU): Queues of processes waiting for I/O. Files sent to printer Simulation of real-world queuing systems (queueing theory): Customers in a grocery store, bank, etc. Orders in a factory Hospital emergency room or doctor s office Telephone calls for airline reservations, customer orders, information, etc. Problem applications: Topological ordering: given a sequence of events, and pairs (a, b) indicating that event a should occur prior to b, provide a schedule. Queues 5 Queues: Circular Array Implementation Previous implementation is O(1) per operation, which is great. However, after n inserts (where n is the size of the array), the array is full even if the queue is logically nearly empty. Solution: Use wraparound to reuse the cells at the start of the array. To increment, add one, but if that goes past end, reset to zero. How do you detect a full or empty queue? We will give a simplified implementation for the queue data structure. A better implementation would detect an empty (full) queue before performing a dequeue (enqueue) operation. Queues 3 Queues: Naïve Implementation Using array: Store items in an array. The head is the first element, and the tail is indicated by tail (we ll have tail point to next available element) insert(x): insert element and increment tail remove() is inefficient: all elements have to be shifted Thus, remove is Θ(n). a b c d tail = 4 remove a b c d tail = 4 update tail b c d How can we improve this? tail = 3 Queues 6 Queue C++ Declaration Here is a C++ declaration of an integer queue using a circular array: ; int Full() return (head==(tail+1)%cap); int Empty() return (head == tail ); class Queue private: int *queue; int cap,head,tail; public: Queue(int s=100) cap= s; queue = new int[cap]; head = 0; tail = 0; Queue() delete [] queue; void Enqueue(int v) queue[tail] = v; tail = (tail+1) % cap; int Dequeue() int t = queue[head]; head = (head + 1) % cap; return t;
2 Queues 7 Queue JAVA Declaration public class Queue private int[] queue; private int cap,head,tail; public Queue(int s) cap=s; queue = new int[cap]; head = 0; tail = 0; public void Enqueue(int v) queue[tail] = v; tail = (tail+1) % cap; public int Dequeue() int t = queue[head]; head = (head + 1) % cap; return t; public int Empty() return (head == tail ); public int Full() return (head == ((tail+1)%cap)); ; Queues 8 Example of Queue Using Circular Array Here we use an array E[0..3] to store the elements and the variables h (head) and t (tail) to keep track of the beginning and end of the queue. The value R is the return value of the operation. Operation h t E0 E1 E2 E3 R create 0 0???? insert(55) ??? insert(-7) ?? insert(16) ? remove() ? 55 insert(-8) remove() remove() insert(11) Note that some of the values remain physically in the array, but are logically no longer in the queue. Queues 9 Queues: Linked List Implementation We can maintain head and tail pointers. remove: advance head. insert: add to end of list and adjust tail. head tail A B C D
3 Chapter Objectives Chapter 8 Queues Learn about queues Examine various queue operations Learn how to implement a queue as an array Learn how to implement a queue as a linked list Data Structures Using C++ 1 Data Structures Using C++ 2 Chapter Objectives Discover queue applications Examine the STL class queue Discover priority queues Queues Definition: data structure in which the elements are added at one end, called the rear or tail, and deleted from the other end, called the front or first First In First Out (FIFO) data structure Data Structures Using C++ 3 Data Structures Using C++ 4 Basic Operations on a Queue initializequeue: Initializes the queue to an empty state destroyqueue: Removes all the elements from the queue, leaving the queue empty isemptyqueue: Checks whether the queue is empty. If the queue is empty, it returns the value true; otherwise, it returns the value false Basic Operations on a queue isfullqueue: Checks whether the queue is full. If the queue is full, it returns the value true; otherwise, it returns the value false front: Returns the front (first) element of the queue; the queue must exist back: Returns the front (first) element of the queue; the queue must exist Data Structures Using C++ 5 Data Structures Using C++ 6
4 Basic Operations on a queue addqueue: Adds a new element to the rear of the queue; the queue must exist and must not be full deletequeue: Removes the front element of the queue; the queue must exist and must not be empty Data Structures Using C++ 7 Data Structures Using C++ 8 Circular Queue Data Structures Using C++ 9 Data Structures Using C++ 10 Data Structures Using C++ 11 Data Structures Using C++ 12
5 Data Structures Using C++ 13 Data Structures Using C++ 14 Data Structures Using C++ 15 Data Structures Using C++ 16 UML Diagram of the class queuetype Data Structures Using C++ 17 Data Structures Using C++ 18
6 Empty Queue and Full Queue Destroy Queue bool queuetype<type>::isemptyqueue() return (count == 0); bool queuetype<type>::isfullqueue() return (count == maxqueuesize); Data Structures Using C++ 19 void queuetype<type>::destroyqueue() queuefront = 0; queuerear = maxqueuesize - 1; count = 0; Data Structures Using C++ 20 front and back Type queuetype<type>::front() assert(!isemptyqueue()); return list[queuefront]; Type queuetype<type>::back() assert(!isemptyqueue()); return list[queuerear]; Data Structures Using C++ 21 Add Queue void queuetype<type>::addqueue(const Type& newelement) if(!isfullqueue()) queuerear = (queuerear + 1) % maxqueuesize; //use the mod //operator to advance queuerear //because the array is circular count++; list[queuerear] = newelement; else cerr<<"cannot add to a full queue."<<endl; Data Structures Using C++ 22 Delete Queue Constructor and Destructor void queuetype<type>::deletequeue() if(!isemptyqueue()) count--; queuefront = (queuefront + 1) % maxqueuesize; //use the mod //operator to advance queuefront //because the array is circular else cerr<<"cannot remove from an empty queue."<<endl; Constructor Creates an array of the size specified by the user Default value is 100 Initializes queuefront queuerear to indicate that the queue is empty Destructor When queue object goes out of scope, destructor reallocates memory occupied by the array that stores the queue elements Data Structures Using C++ 23 Data Structures Using C++ 24
7 Linked Queue as an ADT Empty, Full, and Destroy Queue Queue is empty if queuefront is NULL Queue is full only if we run out of memory Destroy queue removes all elements of the queue Data Structures Using C++ 25 Data Structures Using C++ 26 addqueue Adds a new element to the end of the queue Access the pointer queuerear to implement addqueue Front, Back, and Delete Queue If queue is nonempty: operation front returns the first element of the queue operation back returns the last element of the queue operation deletequeue removes the first element of the queue If queue is empty: function front terminates the program function back terminates the program Data Structures Using C++ 27 Data Structures Using C++ 28 STL class queue (Queue Container Adapter) Priority Queue FIFO rules of a queue are relaxed Customers or jobs with higher priority are pushed to front of queue To implement: use an ordinary linked list, which keeps the items in order from the highest to lowest priority use a treelike structure Data Structures Using C++ 29 Data Structures Using C++ 30
8 Application of Queues Application of Queues Data Structures Using C++ 31 Data Structures Using C++ 32 Application of Queues Application of Queues: waitingcustomerqueuetype Data Structures Using C++ 33 Data Structures Using C++ 34 Chapter Summary Queue Data Structure Restricted Version of arrays and linked list Basic operations First In First Out (FIFO) Queues Implemented as Arrays Chapter Summary Queues Implemented as Linked Lists STL class queue Priority Queues Application of Queues Data Structures Using C++ 35 Data Structures Using C++ 36
Stacks and Queues. Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms
Stacks and Queues Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Two New ADTs Define two new abstract data types Both are restricted lists Can be implemented using arrays
More informationSCJ2013 Data Structure & Algorithms. Queue. Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi
SCJ2013 Data Structure & Algorithms Queue Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi Course Objectives At the end of the lesson students are expected to be able to: Understand queue concepts and
More informationQueue with Array Implementation
Queue with Array Implementation SCSJ2013 Data Structures & Algorithms Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi Faculty of Computing Objectives Queue concepts and applications. Queue structure and
More informationQueue Definition. Ordered list with property:
Queue Definition Ordered list with property: All insertions take place at one end (tail) All deletions take place at other end (head) Queue: Q = (a 0, a 1,, a n-1 ) a0 is the front element, a n-1 is the
More informationData Structures and Algorithms for Engineers
04-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Queues ArrayQueue Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 10, 2014 Abstract These lecture notes are meant to be looked
More informationInsertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue
Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,
More informationLIFO : Last In First Out
Introduction Stack is an ordered list in which all insertions and deletions are made at one end, called the top. Stack is a data structure that is particularly useful in applications involving reversing.
More informationAshish Gupta, Data JUET, Guna
Introduction 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 etc. The person who come first, he/she
More informationCircular Queue can be created in three ways they are: Using single linked list Using double linked list Using arrays
Circular Queue: Implementation and Applications In linear queue, when we delete any element, only front increment by one but position is not used later. So, when we perform more add and delete operations,
More informationLists, Stacks, and Queues. (Lists, Stacks, and Queues ) Data Structures and Programming Spring / 50
Lists, Stacks, and Queues (Lists, Stacks, and Queues ) Data Structures and Programming Spring 2016 1 / 50 Abstract Data Types (ADT) Data type a set of objects + a set of operations Example: integer set
More informationCS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type
More informationChapter 18: Stacks And Queues
Chapter 18: Stacks And Queues 18.1 Introduction to the Stack ADT Introduction to the Stack ADT Stack: a LIFO (last in, first out) data structure Examples: plates in a cafeteria return addresses for function
More informationLecture Data Structure Stack
Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards
More informationChapter 18: Stacks And Queues. Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 18: Stacks And Queues Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Addison-Wesley Pearson Education, Inc. Publishing as Pearson Addison-Wesley 18.1 Introduction to
More informationCSEN 301 Data Structures and Algorithms
CSEN 301 Data Structures and Algorithms Lecture 5: Queues: Implementation and usage Prof. Dr. Slim Abdennadher slim.abdennadher@guc.edu.eg German University Cairo, Department of Media Engineering and Technology
More informationChapter 18: Stacks And Queues
Chapter 18: Stacks And Queues 18.1 Introduction to the Stack ADT Introduction to the Stack ADT Stack a LIFO (last in, first out) data structure Examples plates in a cafeteria return addresses for function
More informationADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )
ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) Unit - 2 By: Gurpreet Singh Dean Academics & H.O.D. (C.S.E. / I.T.) Yamuna Institute of Engineering & Technology, Gadholi What is a Stack? A stack is a
More informationCS24 Week 4 Lecture 2
CS24 Week 4 Lecture 2 Kyle Dewey Overview Linked Lists Stacks Queues Linked Lists Linked Lists Idea: have each chunk (called a node) keep track of both a list element and another chunk Need to keep track
More information1. Introduction. Lecture Content
Lecture 6 Queues 1 Lecture Content 1. Introduction 2. Queue Implementation Using Array 3. Queue Implementation Using Singly Linked List 4. Priority Queue 5. Applications of Queue 2 1. Introduction A queue
More information.:: UNIT 4 ::. STACK AND QUEUE
.:: UNIT 4 ::. STACK AND QUEUE 4.1 A stack is a data structure that supports: Push(x) Insert x to the top element in stack Pop Remove the top item from stack A stack is collection of data item arrange
More informationCHAPTER 5. QUEUE v2 by
CHAPTER 5 QUEUE v2 by www.asyrani.com Queue in C++ [Non-English] It is an ordered group of homogeneous items of elements. [English] You go to the shopping mall on Sunday (peak hour) When it is time for
More information1 P age DS & OOPS / UNIT II
UNIT II Stacks: Definition operations - applications of stack. Queues: Definition - operations Priority queues - De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular
More informationDS Assignment II. Full Sized Image
DS Assignment II 1. A) For the Towers of Hanoi problem, show the call tree during the recursive call Towers(3, A, C, B). In the tree, label the root node as Towers (3, A, C, B) while marking all the intermediate
More informationDEEPIKA KAMBOJ UNIT 2. What is Stack?
What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you
More informationYour Topic Goes Here Queue
Your Subtopics Go Here Your Topic Goes Here Queue Compiled By: Kiran Joshi 1 Queue Roadmap. 1. Definition 2. Queue examples 3. Working of Queue 4. Applications 2 Definition * A data structure of ordered
More informationcsci 210: Data Structures Stacks and Queues
csci 210: Data Structures Stacks and Queues 1 Summary Topics Stacks and Queues as abstract data types ( ADT) Implementations arrays linked lists Analysis and comparison Applications: searching with stacks
More informationCS302 - Data Structures using C++
CS302 - Data Structures using C++ Topic: Queues and Priority Queues Kostas Alexis Implementations of the ADT Queue Like stacks, queues can have Array-based or Link-based implementation Can also use implementation
More informationAbstract Data Types 1
Abstract Data Types 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues 2 Abstract Data Types (ADTs) ADT is a set of objects together with a set of operations. Abstract in that implementation of operations
More informationDynamic Data Structures
Dynamic Data Structures We have seen that the STL containers vector, deque, list, set and map can grow and shrink dynamically. We now examine how some of these containers can be implemented in C++. To
More informationStacks and Queues. CSE Data Structures April 12, 2002
Stacks and Queues CSE 373 - Data Structures April 12, 2002 Readings and References Reading Section 3.3 and 3.4, Data Structures and Algorithm Analysis in C, Weiss Other References 12-Apr-02 CSE 373 - Data
More informationStack and Queue. Stack:
Stack and Queue Stack: Abstract Data Type A stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle. In the pushdown stacks only two operations
More informationMULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR
STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM
More informationAbstract Data Types. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University
Abstract Data Types CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues
More informationQueue: Queue Representation: Basic Operations:
Queue: Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove
More informationAbstract Data Types 1
Abstract Data Types 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues 2 Primitive vs. Abstract Data Types Primitive DT: programmer ADT: programmer Interface (API) data Implementation (methods) Data
More informationAnother common linear data structure similar to. new items enter at the back, or rear, of the queue. Queue is an ADT with following properties
Queues FIFO queue ADT Examples using queues reading character string in order recognize palindromes Queue implementations LL pointer based List ADT based array based tradeoffs 1 ADT queue operations Create
More informationQueues. Gaddis 18.4, Molly A. O'Neil CS 2308 :: Spring 2016
Queues Gaddis 18.4, 18.6 Molly A. O'Neil CS 2308 :: Spring 2016 The Queue ADT A queue is an abstract data type that stores a collection of elements of the same type The elements of a queue are accessed
More informationQueues. Data Structures and Design with Java and JUnit Rick Mercer 18-1
Queues Data Structures and Design with Java and JUnit Rick Mercer 18-1 A Queue ADT First in first out access A Queue is another name for waiting line Example: Submit jobs to a network printer What gets
More informationData Structure. Recitation VII
Data Structure Recitation VII Recursion: Stack trace Queue Topic animation Trace Recursive factorial Executes factorial(4) Step 9: return 24 Step 8: return 6 factorial(4) Step 0: executes factorial(4)
More informationDefinition of Stack. 5 Linked Structures. Stack ADT Operations. ADT Stack Operations. A stack is a LIFO last in, first out structure.
5 Linked Structures Definition of Stack Logical (or ADT) level: A stack is an ordered group of homogeneous items (elements), in which the removal and addition of stack items can take place only at the
More information8. Fundamental Data Structures
172 8. Fundamental Data Structures Abstract data types stack, queue, implementation variants for linked lists, [Ottman/Widmayer, Kap. 1.5.1-1.5.2, Cormen et al, Kap. 10.1.-10.2] Abstract Data Types 173
More informationSTACKS AND QUEUES. Problem Solving with Computers-II
STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()
More informationLECTURE OBJECTIVES 6-2
The Queue ADT LECTURE OBJECTIVES Examine queue processing Define a queue abstract data type Demonstrate how a queue can be used to solve problems Examine various queue implementations Compare queue implementations
More information! A data type for which: ! In fact, an ADT may be implemented by various. ! Examples:
Ch. 8: ADTs: Stacks and Queues Abstract Data Type A data type for which: CS 8 Fall Jill Seaman - only the properties of the data and the operations to be performed on the data are specific, - not concerned
More informationCh. 18: ADTs: Stacks and Queues. Abstract Data Type
Ch. 18: ADTs: Stacks and Queues CS 2308 Fall 2011 Jill Seaman Lecture 18 1 Abstract Data Type A data type for which: - only the properties of the data and the operations to be performed on the data are
More informationMotivation for Queues
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 178] Motivation for Queues Some examples of first-in, first-out (FIFO) behavior: æ waiting in line to check out at a store æ cars on
More informationCMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC
CMSC 341 Lecture 6 Templates, Stacks & Queues Based on slides by Shawn Lupoli & Katherine Gibson at UMBC Today s Topics Data types in C++ Overloading functions Templates How to implement them Possible
More information! A data type for which: ! An ADT may be implemented using various. ! Examples:
Stacks and Queues Unit 6 Chapter 19.1-2,4-5 CS 2308 Fall 2018 Jill Seaman 1 Abstract Data Type A data type for which: - only the properties of the data and the operations to be performed on the data are
More informationUNIT-2 Stack & Queue
UNIT-2 Stack & Queue 59 13. Stack A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards
More informationQueues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1
Queues October 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Queue ADT Queue ADT should support at least the first two operations: enqueue insert an item to the back of the queue dequeue remove an item from
More informationDATA STRUCTURES AND ALGORITHMS LECTURE 08 QUEUES IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD
DATA STRUCTURES AND ALGORITHMS LECTURE 08 S IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD S ABSTRACT DATA TYPE An Abstract Queue (Queue ADT) is an abstract data type that emphasizes specific
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today Introduction to Linked Lists Stacks and Queues using Linked Lists Next Time Iterative Algorithms on Linked Lists Reading:
More informationQueues. CITS2200 Data Structures and Algorithms. Topic 5
CITS2200 Data Structures and Algorithms Topic 5 Queues Implementations of the Queue ADT Queue specification Queue interface Block (array) representations of queues Recursive (linked) representations of
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 5: Stacks and Queues 2017 Fall Stacks A list on which insertion and deletion can be performed. Based on Last-in-First-out (LIFO) Stacks are used for a number of applications:
More informationCOMP 213 Advanced Object-oriented Programming Lecture 8 The Queue ADT (cont.)
COMP 213 Advanced Object-oriented Programming Lecture 8 The Queue ADT (cont.) Recall: The Queue ADT A data structure in which elements enter at one end and are removed from the opposite end is called a
More informationExample Final Questions Instructions
Example Final Questions Instructions This exam paper contains a set of sample final exam questions. It is for practice purposes only. You ll most likely need longer than three hours to answer all the questions.
More informationQueue rear tail front head FIFO
The Queue ADT Objectives Examine queue processing Define a queue abstract data type Demonstrate how a queue can be used to solve problems Examine various queue implementations Compare queue implementations
More informationQueues. Lesson 4. CS 32: Data Structures Dept. of Computer Science
Queues Lesson 4 Outline What is a queue? Straight queue Circular Queue Sequential Implementation Linked Implementation Application: Topological sort Deques Final Notes Outline What is a queue? Straight
More informationWhat Can You Use a Queue For?
Cmpt-225 Queues 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 Out) data structures fair data structures
More informationIntroduction to Data Structures and Algorithms
Introduction to Data Structures and Algorithms Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures
More informationCS200: Queues. Prichard Ch. 8. CS200 - Queues 1
CS200: Queues Prichard Ch. 8 CS200 - Queues 1 Queues First In First Out (FIFO) structure Imagine a checkout line So removing and adding are done from opposite ends of structure. 1 2 3 4 5 add to tail (back),
More informationCS 231 Data Structures and Algorithms Fall DDL & Queue Lecture 20 October 22, Prof. Zadia Codabux
CS 231 Data Structures and Algorithms Fall 2018 DDL & Queue Lecture 20 October 22, 2018 Prof. Zadia Codabux 1 Agenda Mid Semester Analysis Doubly Linked List Queue 2 Administrative None 3 Doubly Linked
More informationA linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list.
A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list. the first element of the list a new element to (the Top of)
More informationName CPTR246 Spring '17 (100 total points) Exam 3
Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in
More informationUNIVERSITY REGULATIONS
CPSC 221: Algorithms and Data Structures Midterm Exam, 2013 February 15 Name: Student ID: Signature: Section (circle one): MWF(201) TTh(202) You have 60 minutes to solve the 5 problems on this exam. A
More informationCMSC Introduction to Algorithms Spring 2012 Lecture 7
CMSC 351 - Introduction to Algorithms Spring 2012 Lecture 7 Instructor: MohammadTaghi Hajiaghayi Scribe: Rajesh Chitnis 1 Introduction In this lecture we give an introduction to Data Structures like arrays,
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 07 / 26 / 2016 Instructor: Michael Eckmann Today s Topics Comments/Questions? Stacks and Queues Applications of both Priority Queues Michael Eckmann - Skidmore
More informationAll the above operations should be preferably implemented in O(1) time. End of the Queue. Front of the Queue. End Enqueue
Module 4: Queue ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Queue ADT Features (Logical View) A List that
More informationAn Introduction to Queues With Examples in C++
An Introduction to Queues With Examples in C++ Prof. David Bernstein James Madison University Computer Science Department bernstdh@jmu.edu Motivation Queues are very straightforward but are slightly more
More informationLecture Notes CPSC 122 (Fall 2014) Today Quiz 7 Doubly Linked Lists (Unsorted) List ADT Assignments Program 8 and Reading 6 out S.
Today Quiz 7 Doubly Linked Lists (Unsorted) List ADT Assignments Program 8 and Reading 6 out S. Bowers 1 of 11 Doubly Linked Lists Each node has both a next and a prev pointer head \ v1 v2 v3 \ tail struct
More informationQueues COL 106. Slides by Amit Kumar, Shweta Agrawal
Queues COL 106 Slides by Amit Kumar, Shweta Agrawal The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out (FIFO) scheme Insertions are at the rear
More informationIntroduction to the C programming language
Introduction to the C programming language From C to C++: Stack and Queue Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 23, 2010 Outline 1 From struct to classes
More informationStacks and Queues III
EE Data Structures and lgorithms http://www.ecs.umass.edu/~polizzi/teaching/ee/ Stacks and Queues III Lecture 8 Prof. Eric Polizzi Queues overview First In First Out (FIFO) Input D Output Queues allow
More information1/22/13. Queue? CS 200 Algorithms and Data Structures. Implementing Queue Comparison implementations. Photo by David Jump 9. Colorado State University
//3 Part Queues CS Algorithms and Data Structures Outline Queue? Implementing Queue Comparison implementations 8 Photo by David Jump 9 //3 "Grill the Buffs" event Queue A queue is like a line of people
More information1/22/13. Queue. Create an empty queue Determine whether a queue is empty Add a new item to the queue
Outline Part Queues Queue? Implementing Queue Comparison implementations CS Algorithms and Data Structures 8 "Grill the Buffs" event Photo by David Jump 9 Queue A queue is like a line of people New item
More informationPriority Queue ADT. Revised based on textbook author s notes.
Priority Queue ADT Revised based on textbook author s notes. Priority Queues Some applications require the use of a queue in which items are assigned a priority. higher priority items are dequeued first.
More informationIntroduction to the C programming language
Introduction to the C programming language From C to C++: Stack and Queue Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 23, 2010 Outline 1 From struct to classes
More informationDiscussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:
Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let
More informationADT: Design & Implementation
CPSC 250 Data Structures ADT: Design & Implementation Dr. Yingwu Zhu Abstract Data Type (ADT) ADT = data items + operations on the data Design of ADT Determine data members & operations Implementation
More informationADTs: Stacks and Queues
Introduction to the Stack ADTs: Stack: a data structure that holds a collection of elements of the same type. - The elements are accessed according to LIFO order: last in, first out - No random access
More informationEC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3
UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between
More informationQueue? Part 4. Queues. Photo by David Jump. Create an empty queue Items leave a queue from its front.
/3/ Outline Queue? Part Queues Implementing Queue Comparison implementations CS Algorithms and Data Structures "Grill the Buffs" event 9/ 3 Photo by David Jump Queue OperaLons A queue is like a line of
More informationContainers: Queue and List. Jordi Cortadella and Jordi Petit Department of Computer Science
Containers: Queue and List Jordi Cortadella and Jordi Petit Department of Computer Science Queue A container in which insertion is done at one end (the tail) and deletion is done at the other end (the
More informationKeeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10
Keeping Order:! Stacks, Queues, & Deques 1 Stacks 2 Stacks A stack is a last in, first out (LIFO) data structure Primary Operations: push() add item to top pop() return the top item and remove it peek()
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 6: Stacks and Queues 2015-2016 Fall Stacks A list on which insertion and deletion can be performed. Based on Last-in-First-out (LIFO) Stacks are used for a number of applications:
More informationQueues Fall 2018 Margaret Reid-Miller
Queues 15-121 Fall 2018 Margaret Reid-Miller Today Exam 2 is next Tuesday, October 30 Writing methods various classes that implement Lists. Methods using Lists and Big-O w/ ArrayList or LinkedLists Prove
More informationCE204 Data Structures and Algorithms Part 2
CE204 Data Structures and Algorithms Part 2 14/01/2018 CE204 Part 2 1 Abstract Data Types 1 An abstract data type is a type that may be specified completely without the use of any programming language.
More information1.00 Lecture 26. Data Structures: Introduction Stacks. Reading for next time: Big Java: Data Structures
1.00 Lecture 26 Data Structures: Introduction Stacks Reading for next time: Big Java: 19.1-19.3 Data Structures Set of primitives used in algorithms, simulations, operating systems, applications to: Store
More informationData Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1
Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Infix to Postfix Example 1: Infix to Postfix Example 2: Postfix Evaluation
More informationAnnouncements Queues. Queues
Announcements. Queues Queues A queue is consistent with the general concept of a waiting line to buy movie tickets a request to print a document crawling the web to retrieve documents A queue is a linear
More information1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University
Chapter 5: Stacks, ueues and Deques Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,
More informationCMPT 125: Practice Midterm Answer Key
CMPT 125, Spring 2017, Surrey Practice Midterm Answer Key Page 1 of 6 CMPT 125: Practice Midterm Answer Key Linked Lists Suppose you have a singly-linked list whose nodes are defined like this: struct
More informationQueue ADT. January 31, 2018 Cinda Heeren / Geoffrey Tien 1
Queue ADT Cinda Heeren / Geoffrey Tien 1 PA1 testing Your code must compile with our private test file Any non-compiling submissions will receive zero Note that only functions that are called will be compiled
More informationStacks and Queues. Introduction to abstract data types (ADTs) Stack ADT. Queue ADT. Time permitting: additional Comparator example
Stacks and Queues Introduction to abstract data types (ADTs) Stack ADT applications interface for Java Stack ex use: reverse a sequence of values Queue ADT applications interface for Java Queue Time permitting:
More informationSubject : Computer Science. Paper: Data Structures. Module: Priority Queue and Applications. Module No: CS/DS/14
e-pg Pathshala Subject : Computer Science Paper: Data Structures Module: Priority Queue and Applications Module No: CS/DS/14 Quadrant 1- e-text Welcome to the e-pg Pathshala Lecture Series on Data Structures.
More information(6-1) Basics of a Queue. Instructor - Andrew S. O Fallon CptS 122 (September 26, 2018) Washington State University
(6-1) Basics of a Queue Instructor - Andrew S. O Fallon CptS 122 (September 26, 2018) Washington State University What is a Queue? 2 A linear data structure with a finite sequence of nodes, where nodes
More information12 Abstract Data Types
12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define
More informationExtra Credit: write mystrlen1 as a single function without the second parameter int mystrlen2(char* str)
CPSC 122 Study Guide 3: Final Examination The final examination will consist of three parts: Part 1 covers mostly C++. For this, see study guides 1 and 2, exams 1 and 2, and part of exam 3, and quizzes
More informationCMSC 341 Lecture 6 STL, Stacks, & Queues. Based on slides by Lupoli, Dixon & Gibson at UMBC
CMSC 341 Lecture 6 STL, Stacks, & Queues Based on slides by Lupoli, Dixon & Gibson at UMBC Templates 2 Common Uses for Templates Some common algorithms that easily lend themselves to templates: Swap what
More information