CSEN 301 Data Structures and Algorithms
|
|
- Andrew Heath
- 6 years ago
- Views:
Transcription
1 CSEN 301 Data Structures and Algorithms Lecture 5: Queues: Implementation and usage Prof. Dr. Slim Abdennadher German University Cairo, Department of Media Engineering and Technology Abdennadher (GUC MET) CSEN / 23
2 Synopsis Synopsis (ADT, stack) Synopsis: Object Stacks and Interfaces How can I construct a generic stack? How can I use a generic stack with primitive data structures? What is an interface? What information does it contain? What is not part of the interface? What is the meaning of the interface in terms of the inside- or outside-view of a class? Abdennadher (GUC MET) CSEN / 23
3 Queue Queues Queues general idea Queue: First Come First Serve Examples: Toll Station: Car comes, pays, leaves Check-out in Big Market: Customer comes, checks out, and leaves Print Server: jobs are printed according to the arrival time More examples: Office hours, Airport security check,... Abdennadher (GUC MET) CSEN / 23
4 Queues Queues general idea What is a Queue? Queue is an abstract data type Adding an entry at the rear (Enqueue). Deleting an entry at the front (DeQueue). A queue is open at two ends. Queue is a first-in first-out (FIFO) sequence of elements. Note that you you can not add/extract entry in the middle of the queue Abdennadher (GUC MET) CSEN / 23
5 Main queue operations Queues Queue basics In a queue, all operations take place at one end or the other. Front original queue Back The dequeue-operation removes an item at the front Front after dequeue() Back The enqueue-operation adds an item to the back Front after enqueue(83) Back Abdennadher (GUC MET) CSEN / 23
6 Queues Queue basics Queue operations synopsis enqueue: add a new item at the rear (back) dequeue: remove an item form the front isempty: check whether the queue is empty or not isfull: check whether the queue is full or not size: return the number of items in the queue peek: return the front item Abdennadher (GUC MET) CSEN / 23
7 Queues Implementing a queue basics Queue implementation ideas A queue can be implemented with an array. We need: The array itself, A front-pointer, A rear-pointer. front rear Front Back Abdennadher (GUC MET) CSEN / 23
8 Queues Queue implementation ideas Implementing a queue problem front rear Front Back Does anybody see a problem? An array has limited size! Once rear is at the end of this array, what do we do? Front front Array implementation rear 42 Back Abdennadher (GUC MET) CSEN / 23
9 front Queues Implementing a queue principle Queue implementation ideas Front front rear 42 Back Solution 1: Shifting the elements Too costly! Solution 2: Wrapping the the array around as a circular store rear Back Front Abdennadher (GUC MET) CSEN / 23
10 Queue class Queues Queue implementation using arrays of integers Instance Variables and Constructor public class Queue { private int maxsize; private int[] quearray; private int front; private int rear; private int nitems; // Maximum Capacity for the queue // The array that holds the items // constructor public Queue(int s) { maxsize = s; quearray = new int[maxsize]; front = 0; rear = -1; nitems = 0; } // end of constructor // set array size // create array // no items yet Abdennadher (GUC MET) CSEN / 23
11 Queue methods I Queues Queue implementation using arrays of integers enqueue public void enqueue(int i) { if (rear == maxsize - 1) rear = -1; quearray[++rear] = i; // increment rear, insert item nitems++; } dequeue public int dequeue() { int result = quearray[front]; front++; if (front == maxsize) front = 0; nitems--; return result; } // get value // increment front // deal with wraparound Abdennadher (GUC MET) CSEN / 23
12 Queue methods II Queues Queue implementation using arrays of integers peek isempty isfull size public int peek() { return quearray[front]; } public boolean isempty() { return (nitems == 0); } public boolean isfull() { return (nitems == maxsize); } public int size() { return nitems; } Abdennadher (GUC MET) CSEN / 23
13 Using a queue Queues Queue usage To use the array implementation: Queue thequeue = new Queue(10); thequeue.enqueue(2); thequeue.enqueue(3); Check isempty before using dequeue or peek while (! thequeue.isempty()) { int value = thequeue.dequeue(); System.out.print(value); System.out.print(" "); } Abdennadher (GUC MET) CSEN / 23
14 Using a queue Queues Queue usage Check isfull before using enqueue if (! thequeue.isfull()) thequeue.enqueue(item); else System.out.println("Can t insert, queue is full"); } Abdennadher (GUC MET) CSEN / 23
15 Queues Excursion Infering the item-count Question Can we implement the queue without keeping track of the item count nitems? Why? Item Count may influence performance if dealing with huge number of insertions and deletions. Not necessary? Without an item count we can still rely on front and rear to figure out whether the queue is empty or full to figure out the number of items in general Does anybody see a problem? How do you distinguish and empty queue from a full queue? Abdennadher (GUC MET) CSEN / 23
16 Queues Excursion Infering the item-count rear rear rear front front front Start with an empty queue Enqueue 125, 8, 22, 17, 83, , 64, 92. The queue is full, but the relative position of front and rear is the same as empty! Abdennadher (GUC MET) CSEN / 23
17 Queues Excursion Infering the item-count rear rear rear front front front The problem only occurs when the queue becomes completely full! One solution is to make the array one position bigger than the maximum of items. An implementation can be found in the textbook, pp.141f Abdennadher (GUC MET) CSEN / 23
18 Queues Queues of objects Question Queue is an abstract data structure. Item can be Integer, Double, String, also can be any data type, such as Employee, Faculty,... How to implement a generic (general) for all those types? Same as Stack, we use Object data type instead of int or double or String or other data type. Use an array in Queue, which stores all items come in Object[] Queue; Other implementations are possible. Abdennadher (GUC MET) CSEN / 23
19 Queues Queue of objects class Queues of objects Instance Variables and Constructor public class ObjectQueue { private int maxsize; // Maximum Capacity for the queue private Object[] quearray; // The array that holds the items private int front; private int rear; private int nitems; // constructor public ObjectQueue(int s) { maxsize = s; // set array size quearray = new Object[maxSize]; // create array front = 0; rear = -1; nitems = 0; // no items yet } // end of constructor Abdennadher (GUC MET) CSEN / 23
20 Queues Queues of objects Queue of objects some methods enqueue public void enqueue(object o) { if (rear == maxsize - 1) rear = -1; quearray[++rear] = o; // increment rear, insert item nitems++; } dequeue public Object dequeue() { Object result = quearray[front];// get value front++; // increment front if (front == maxsize) // deal with wraparound front = 0; nitems--; return result; } Abdennadher (GUC MET) CSEN / 23
21 Queues Queues of objects How to use the Generic Queue Class Create two queues with 10 elements Queue charqueue = new Queue(10); Queue empqueue = new Queue(10); enqueue and dequeue characters in Queue charqueue charqueue.enqueue(new Character( a )); char ch = (Character) charqueue.dequeue().charvalue(); enqueue and dequeue Employee in Queue empqueue empqueue.enqueue( new Employee("Bush", "2233")); Employee emp = (Employee) empqueue.dequeue(); Abdennadher (GUC MET) CSEN / 23
22 Example Queues Queue examples Print job management: Three documents are ready to print. Output the printer status Enqueue the documents public void printstatus() { Queue que = new Queue( ); //Create a new queue // print the printer status System.out.println("Printing job: Null "); // new printing jobs come, a.doc, b.doc, c.doc System.out.println("New printing job: a.doc"); que.enqueue( "a.doc" ); System.out.println("New printing job: que.enqueue( "b.doc" ); System.out.println("New printing job: que.enqueue( "c.doc" ); b.doc"); c.doc"); Abdennadher (GUC MET) CSEN / 23
23 Example Queues Queue examples Print job management: Three documents are ready to print. Which document is finished? } // print the printer status System.out.println("\nPrinting job: there are " + que.size() + "jobs in the queue"); System.out.println(" " + que.dequeue() + " is Finished"); System.out.println(" " + que.dequeue() + " is Finished"); System.out.println(" " + que.dequeue() + " is Finished"); Abdennadher (GUC MET) CSEN / 23
Stacks 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 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 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 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 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 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 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 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 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 informationStacks and Queues. CSE 373 Data Structures Lecture 6
Stacks and Queues CSE 373 Data Structures Lecture 6 Readings and References Reading Sections 3.3 and 3.4 10/11/02 Stacks and Queues - Lecture 6 2 Stacks A list for which Insert and Delete are allowed only
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 informationCSE 373 Data Structures and Algorithms. Lecture 2: Queues
CSE 373 Data Structures and Algorithms Lecture 2: Queues Queue ADT queue: A list with the restriction that insertions are done at one end and deletions are done at the other First-In, First-Out ("FIFO
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 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 informationData Structures and Algorithms Winter Semester
Page 0 German University in Cairo October 24, 2018 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher Dr. Wael Abouelsadaat Data Structures and Algorithms Winter Semester 2018-2019 Midterm
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 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 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 informationHow can we improve this? Queues 6. Topological ordering: given a sequence of. should occur prior to b, provide a schedule. Queues 5.
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:
More informationCPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues
CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.
More informationCSC 1052 Algorithms & Data Structures II: Queues
CSC 1052 Algorithms & Data Structures II: Queues Professor Henry Carter Spring 2018 Recap Recursion solves problems by solving smaller version of the same problem Three components Applicable in a range
More informationQueues. Virtuelle Fachhochschule. Prof. Dr. Debora Weber-Wulff
Queues Virtuelle Fachhochschule Prof. Dr. Debora Weber-Wulff!1 Queues First In, First Out Well-known in socialist society Operations enqueue join the back of the line dequeue remove from the front of the
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) An interesting definition for stack element The stack element could be of any data type struct stackelement int etype; union int ival;
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 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 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 informationAbstract Data Types. Abstract Data Types
Abstract Data Types Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria Wolfgang.Schreiner@risc.jku.at http://www.risc.jku.at Wolfgang Schreiner
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 informationCPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues
CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 available very
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 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 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 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 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 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 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 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 informationCSEN 202 Introduction to Computer Programming
CSEN 202 Introduction to Computer Programming Lecture 3: Decisions Prof. Dr. Slim Abdennadher and Dr Mohammed Abdel Megeed Salem, slim.abdennadher@guc.edu.eg German University Cairo, Department of Media
More informationCSE 214 Computer Science II Heaps and Priority Queues
CSE 214 Computer Science II Heaps and Priority Queues Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction
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 informationWentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.
Lecture 11 1 More Data Structures In this lecture we will use a linked list to implement two abstract data types (ADT) An ADT provides the interface, or what a data structure does We can then use code
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 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. Queue ADT Queue Implementation Priority Queues
Queues Queue ADT Queue Implementation Priority Queues Queue A restricted access container that stores a linear collection. Very common for solving problems in computer science that require data to be processed
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 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 informationCSCD 326 Data Structures I Queues
CSCD 326 Data Structures I Queues 1 Linked List Queue Implementation Diagram Front Back A B C D 0 6 public interface QueueInterface { Queue Interface public boolean isempty(); // Determines whether
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 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 informationLinked List. April 2, 2007 Programming and Data Structure 1
Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element
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 informationCSEN 202 Introduction to Computer Programming
CSEN 202 Introduction to Computer Programming Lecture 4: Iterations Prof. Dr. Slim Abdennadher and Dr Mohammed Abdel Megeed Salem, slim.abdennadher@guc.edu.eg German University Cairo, Department of Media
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 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 informationChapter 2. Stack & Queues. M hiwa ahmad aziz
. Chapter 2 Stack & Queues www.raparinweb.com M hiwa ahmad aziz 1 Stack A stack structure with a series of data elements that Allows access to only the last item inserted. An item is inserted or removed
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 informationCMSC 132: Object-Oriented Programming II. Stack and Queue
CMSC 132: Object-Oriented Programming II Stack and Queue 1 Stack Allows access to only the last item inserted. An item is inserted or removed from the stack from one end called the top of the stack. This
More information1. Stack Implementation Using 1D Array
Lecture 5 Stacks 1 Lecture Content 1. Stack Implementation Using 1D Array 2. Stack Implementation Using Singly Linked List 3. Applications of Stack 3.1 Infix and Postfix Arithmetic Expressions 3.2 Evaluate
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 informationData Structures and Algorithms, Winter term 2018 Practice Assignment 3
German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Wael Abouelsaadat Data Structures and Algorithms, Winter term 2018 Practice Assignment 3 Exercise 3-1 Search in
More information! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade
Final Exam Review Final Exam Mon, May 5, 2:00PM to 4:30PM CS 2308 Spring 2014 Jill Seaman Closed book, closed notes, clean desk Comprehensive (covers entire course) 30% of your final grade I recommend
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 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 informationdouble d0, d1, d2, d3; double * dp = new double[4]; double da[4];
All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers
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 information03/29/2004. A dispenser has three essential features: adding, removing, accessing. Dispensers
Dispensers stacks queues priority queues Dictionaries A dispenser is a container that restricts access to its elements. Only one element in the container can be accessed or removed. This element is called
More informationStandard ADTs. Lecture 19 CS2110 Summer 2009
Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2
More informationIntroduction to the Stack. Stacks and Queues. Stack Operations. Stack illustrated. elements of the same type. Week 9. Gaddis: Chapter 18
Stacks and Queues Week 9 Gaddis: Chapter 18 CS 5301 Fall 2015 Jill Seaman Introduction to the Stack Stack: a data structure that holds a collection of elements of the same type. - The elements are accessed
More informationQueues. Stacks and Queues
Queues Reading: RS Chapter 14 Slides are modified from those provided by Marty Stepp www.buildingjavaprograms.com 1 Stacks and Queues Sometimes a less powerful, but highly optimized collection is useful.
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 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 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 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 informationData Structures. Lecture 5 : The Queues
0 Data Structures Lecture 5 : Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University http://bu.edu.eg/staff/esamhalim14 2 A queue is logically a first in first out (FIFO
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. 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 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 informationProgramming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras
Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 13 Merging using Queue ADT and Queue types In the
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 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 informationCSC 1052 Algorithms & Data Structures II: Linked Queues
CSC 1052 Algorithms & Data Structures II: Linked Queues Professor Henry Carter Spring 2018 Recap A queue simulates a waiting line, where objects are removed in the same order they are added The primary
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 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 informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) The queue ADT A queue is like a "natural" queue of elements. It is an ordered list in which all insertions occur at one end called
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 informationCMPSCI 187: Programming With Data Structures. Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012
CMPSCI 187: Programming With Data Structures Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012 Implementing Stacks With Arrays The Idea of the Implementation Data Fields
More informationBasic Data Structures
Basic Data Structures Some Java Preliminaries Generics (aka parametrized types) is a Java mechanism that enables the implementation of collection ADTs that can store any type of data Stack s1
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 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 informationCSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam
Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code
More informationBuilding Java Programs
Building Java Programs Appendix Q Lecture Q-1: stacks and queues reading: appendix Q 2 Runtime Efficiency (13.2) efficiency: measure of computing resources used by code. can be relative to speed (time),
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 informationA queue is a linear collection whose elements are added on one end and removed from the other
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 Adding an element Removing an element A queue
More informationCSE 373 SEPTEMBER 29 STACKS AND QUEUES
CSE 373 SEPTEMBER 29 STACKS AND QUEUES DESIGN DECISIONS Shopping list? DESIGN DECISIONS Shopping list? What sorts of behavior do shoppers exhibit? What constraints are there on a shopper? What improvements
More information== isn t always equal?
== isn t always equal? In Java, == does the expected for primitives. int a = 26; int b = 26; // a == b is true int a = 13; int b = 26; // a == b is false Comparing two references checks if they are pointing
More informationBasic Data Structures 1 / 24
Basic Data Structures 1 / 24 Outline 1 Some Java Preliminaries 2 Linked Lists 3 Bags 4 Queues 5 Stacks 6 Performance Characteristics 2 / 24 Some Java Preliminaries Generics (aka parametrized types) is
More informationQueues. ADT description Implementations. October 03, 2017 Cinda Heeren / Geoffrey Tien 1
Queues ADT description Implementations Cinda Heeren / Geoffrey Tien 1 Queues Assume that we want to store data for a print queue for a student printer Student ID Time File name The printer is to be assigned
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 informationData Structures and Algorithms Winter term 2012
Page 0 German University in Cairo November 4, 2012 Faculty of Media Engineering and Technology Prof. Dr. Slim Abdennadher Data Structures and Algorithms Winter term 2012 Midterm Exam Bar Code Instructions:
More information