Stacks and Queues Introduction to Computing Science and Programming I.

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

Stacks and Queues. Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about.
Stack & Queues COP 3502.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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.
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
CS Data Structures II Review COSC 2006 April 14, 2017
Lecture 12 – ADTs and Stacks.  Modularity  Divide the program into smaller parts  Advantages  Keeps the complexity managable  Isolates errors (parts.
Data Structures - Stacks. What are data structures? Different ways to organize data What data structures have we used before? lists / arrays Deck (AceyDeucey)
Chapter 13 Queues and Priority Queues CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Data Structures & Algorithms
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Data Structures: Lists i206 Fall 2010 John Chuang Some slides adapted from Glenn Brookshear, Brian Hayes, or Marti Hearst.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
COMP 110 Introduction to Programming Mr. Joshua Stough.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
Stacks, Queues, and Deques
Stacks, Queues, and Deques. 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.
Stacks, Queues, and Deques
Queues and Priority Queues
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
Copyright © Texas Education Agency, Advanced Computer Programming Data Structures: Collections.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
Mastering STACKS AN INTRODUCTION TO STACKS Data Structures.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
CMSC 202 Stacks and Queues. What’s a Queue? A queue is a linear collection of homogeneous data in which items added to the queue must be placed at the.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 3.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
Arrays and Collections Tonga Institute of Higher Education.
Chapter 8 Queues. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
3/3/20161 Stacks and Queues Introduction to Data Structures Ananda Gunawardena.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15 1.
Chapter 7 A Queues. © 2004 Pearson Addison-Wesley. All rights reserved7 A-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear,
Click to edit Master text styles Stacks Data Structure.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Data Structures Intro2CS – week Stack ADT (Abstract Data Type) A container with 3 basic actions: – push(item) – pop() – is_empty() Semantics: –
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Chapter 15 Lists Objectives
Objectives In this lesson, you will learn to: Define stacks
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
Stacks and Queues.
Building Java Programs
i206: Lecture 11: Stacks, Queues
i206: Lecture 10: Lists, Stacks, Queues
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Lesson Objectives Aims
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Abstract Data Type Abstract Data Type as a design tool
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Visit for more Learning Resources
Stacks, Queues, and Deques
Stacks.
Queues Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
DATA STRUCTURES IN PYTHON
Presentation transcript:

Stacks and Queues Introduction to Computing Science and Programming I

Data Structures Data structures are different structures that can be used to store data. Different structures will organize it differently causing differences in how the data is accessed and changed. Data structures are different structures that can be used to store data. Different structures will organize it differently causing differences in how the data is accessed and changed. The only data structure we’ve used in Python is the list. The only data structure we’ve used in Python is the list.

Abstract Data Type We’re going to talk about a couple abstract data types. We’re only going to look at them in a very general, abstract way. We won’t worry about details of how to implement the structures in Python. We will only discuss how the data is organized and what operations can be performed on it. We’re going to talk about a couple abstract data types. We’re only going to look at them in a very general, abstract way. We won’t worry about details of how to implement the structures in Python. We will only discuss how the data is organized and what operations can be performed on it. The structures can be used in any programming language. The structures can be used in any programming language.

Queues A queue is a simple data structure that is works similar to a line of people (a queue) waiting to be helped by a cashier. A queue is a simple data structure that is works similar to a line of people (a queue) waiting to be helped by a cashier. You can only add or remove items one at a time. You can only add or remove items one at a time. It is a First In First Out, FIFO data structure. The first item you put in will be the first item that leaves the queue. It is a First In First Out, FIFO data structure. The first item you put in will be the first item that leaves the queue.

Queues \ / Entrance -> -> Exit / \ Every queue has to basic operations. Every queue has to basic operations. queue(Item) adds the item to the queue queue(Item) adds the item to the queue dequeue() removes an item from the queue dequeue() removes an item from the queue Some operations that many queues have, but aren’t required. Some operations that many queues have, but aren’t required. size() number of elements in the queue size() number of elements in the queue isEmpty() check whether there are any items isEmpty() check whether there are any items peek() Look at the next item to be removed without removing it peek() Look at the next item to be removed without removing it

Queues \ / Entrance -> > Exit / \ This is what the queue would look like after the following operations. This is what the queue would look like after the following operations. queue(8) queue(8) queue(10) queue(10) queue(5) queue(5) If the items we’re removed using the dequeue operation, they would be returned in the order they were put it, 8, then 10, and finally 5. If the items we’re removed using the dequeue operation, they would be returned in the order they were put it, 8, then 10, and finally 5.

Queues Remember that these queues and any other structure can store numbers, strings, or objects of any kind. Remember that these queues and any other structure can store numbers, strings, or objects of any kind. Applications of the queue have to do with resource management and requests. For example if you send several documents to be printed, they will be put in a queue before being printed one at a time in the order they were added. Applications of the queue have to do with resource management and requests. For example if you send several documents to be printed, they will be put in a queue before being printed one at a time in the order they were added.

Stacks A stack is a simple data structure that works similarly to a stack of papers. You can only add elements to the top and also only remove them from the top. A stack is a simple data structure that works similarly to a stack of papers. You can only add elements to the top and also only remove them from the top. This makes it a Last In First Out, LIFO, structure because the last item added will be the first one removed. This makes it a Last In First Out, LIFO, structure because the last item added will be the first one removed.

Stacks Enter -> -> Exit Enter -> -> Exit | | Every stack has to basic operations. Every stack has to basic operations. push(Item) adds the item to the top of the stack, “pushing” the others down push(Item) adds the item to the top of the stack, “pushing” the others down pop() removes an item from the top of the stack pop() removes an item from the top of the stack Some operations that many stacks have, but aren’t required. Some operations that many stacks have, but aren’t required. size() number of elements in the stack size() number of elements in the stack isEmpty() check whether there are any items isEmpty() check whether there are any items peek() Look at the next item to be removed without removing it peek() Look at the next item to be removed without removing it

Stacks Enter -> -> Exit Enter -> -> Exit | 5 | | 10| | 8| This is what the stack would look like after the following operations. This is what the stack would look like after the following operations. push(8) push(8) push(10) push(10) push(5) push(5) If the items we’re removed using the pop operation, they would be returned in the reverse of the order they were put it, 5, then 10, and finally 8. If the items we’re removed using the pop operation, they would be returned in the reverse of the order they were put it, 5, then 10, and finally 8.

Stacks Stacks are used in a wide array of applications. They can be used to evaluate equations as well as keep track of function calls in a program that is running. Stacks are used in a wide array of applications. They can be used to evaluate equations as well as keep track of function calls in a program that is running.