Stacks and Queues. Introduction to abstract data types (ADTs) Stack ADT. Queue ADT. Time permitting: additional Comparator example

Size: px
Start display at page:

Download "Stacks and Queues. Introduction to abstract data types (ADTs) Stack ADT. Queue ADT. Time permitting: additional Comparator example"

Transcription

1 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: additional Comparator example Stacks & Queues [Bono] 1

2 Announcements PA3 due after Spring break Claire s office hours today (3/8): 1:15-3:15 Howards office hour tomorrow (3/9): 4 5 only Sample MT 2 exams will be posted soon. Stacks & Queues [Bono] 2

3 Abstract Data Types (ADTs) An abstract idea of a data structure Can be implemented with a class ADT operations = class methods Some ADT examples: Stack, Queue, Set, Map Some concrete data structure examples: array, linked list, hash table. The ADT is implemented as a class that encapsulates a concrete data structure, and often has more than one possible implementation Can also be modeled using Java interface feature and classes that implement the interface Stacks & Queues [Bono] 3

4 Stacks a collection of things (like an array is) but with restricted access the only item you can look at or remove is the last item you inserted. Last In First Out (LIFO). E.g. stack of dishes push a plate on the top of the stack pop a plate from the top of the stack examine the plate at the top of the stack ask if the stack is empty Stacks & Queues [Bono] 4

5 Stacks for method call/return a second example of a stack is the system stack (a.k.a., runtime stack, or call stack) element is called a stack frame (aka, activation record): all the data associated with that call: e.g., locals, params, return addr. method call/return follows LIFO order. last method called will return before any ones that called it. Let s look at an example: void main() { B(); D(); B(); } void B() { C(); D(); } void C() { D(); } void D() { return; } Stacks & Queues [Bono] 5

6 Example of method call/return void main() { B(); D(); B(); } void B() { C(); D(); } void C() { D(); } void D() { return; } Stacks & Queues [Bono] 6

7 import java.util.stack; Java Stack class Stack<Integer> s = new Stack<Integer>(); // creates an empty stack s.push(3); // add an element to the top of // the stack int n = s.peek(); // returns top element in the // stack (does not modify stack) int top = s.pop(); // pops top element off of // stack and returns it s.empty(); // tells whether stack is empty Stacks & Queues [Bono] 7

8 Using Stack operations Stack<Character> s = new Stack<Character>(); // creates an empty stack of characters s.push( a ); s.push( b ); s.push( c ); System.out.println(s.peek()); s.pop(); s.push( d ); System.out.println(s.peek()); s.pop(); s.pop(); System.out.println(s.empty()); Stacks & Queues [Bono] 8

9 Ex: Reversing a sequence Stacks are good for reversing things The last item you put on is the first one you get out The second to last item you put on will be the second item you get out, etc. Example problem: read in a bunch of integer values and then print them out in reverse order. Stacks & Queues [Bono] 9

10 Stack representations How to represent? Where should top be? What is big-o of each operation? Stacks & Queues [Bono] 10

11 Queue A container of elements that can be accessed/inserted/removed like standing in line. Enter queue at the end (enqueue) Exit queue at the front (dequeue) Can access front element First-in First-out (FIFO) Stacks & Queues [Bono] 11

12 Applications of Queues Major application is to represent lines (queues) in software. E.g., big in operating systems print queue print jobs waiting to print. They are processed in FIFO order. process queue processes waiting for their turn to execute. Stacks & Queues [Bono] 12

13 Queue applications (cont.) also in simulations queue of events waiting to be processed simulating queues from the world we are simulating (e.g., Bank line, airplanes waiting to take off) and Java GUI system queue of user input events waiting to be processed (e.g., mouse clicks, keyboard strokes) Stacks & Queues [Bono] 13

14 Java Queue Queue is an interface rather than a class. LinkedList implements this interface. To create one: Queue<MyType> q = new LinkedList<MyType>(); means we intend to only use the LL ops specified by Queue. Stacks & Queues [Bono] 14

15 import java.util.queue; Java Queue interface import java.util.linkedlist; Queue<Integer> q = new LinkedList<Integer>(); // creates an empty queue of integers q.add(3); // add an element to the end int n = q.peek(); // returns first element in // the queue (does not modify queue) int front = q.remove(); // removes first element from queue // and returns it q.isempty(); // tells whether queue is empty Stacks & Queues [Bono] 15

16 Using queue operations Queue<Character> q = new LinkedList<Character>(); q.add( a ); q.add( b ); q.add( c ); System.out.println(q.peek()); q.remove(); q.add( d ); System.out.println(q.peek()); q.remove(); q.remove(); System.out.println(q.isEmpty()); Stacks & Queues [Bono] 16

17 Queue representations How to represent? Where is front and end? What is big-o of each operation? Stacks & Queues [Bono] 17

18 Related data structures Why is Queue an interface? some other queue implementations are used in multi-thread Java applications one queue implementation is a priority queue not FIFO, but an element s priority determines how soon it gets to the front of the line. Stacks & Queues [Bono] 18

19 Additional Comparator example Problem: sort an array of Rectangle s in increasing order by area. Do not implement your own sort method! public static void sortincrbyarea( Rectangle[] rects) { Arrays.sort( Stacks & Queues [Bono] 19

CSE 143. Lecture 4: Stacks and Queues

CSE 143. Lecture 4: Stacks and Queues CSE 143 Lecture 4: Stacks and Queues Stacks and queues Sometimes it is good to have a collection that is less powerful, but is optimized to perform certain operations very quickly. Today we will examine

More information

Queues. Stacks and Queues

Queues. 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

Building Java Programs

Building 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 information

CSE 373 Data Structures and Algorithms. Lecture 2: Queues

CSE 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 information

CS 206 Introduction to Computer Science II

CS 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 information

Stacks and Queues

Stacks and Queues Stacks and Queues 2-25-2009 1 Opening Discussion Let's look at solutions to the interclass problem. Do you have any questions about the reading? Do you have any questions about the assignment? Minute Essays

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 B Cynthia Lee Today s Topics ADTs Stack Example: Reverse-Polish Notation calculator Queue Example: Mouse Events Stacks New ADT: Stack stack.h template

More information

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II CS 206 Introduction to Computer Science II 03 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions? Comments? finish RadixSort implementation some applications of stack Priority Queues Michael

More information

C Sc 127B Practice Test 2 Section Leader Your Name 100pts

C Sc 127B Practice Test 2 Section Leader Your Name 100pts C Sc 127B Practice Test 2 Section Leader Your Name 100pts Assume we have two collection class named Stack and Queue that have the appropriate messages: Stack public boolean isempty(); public void push(e

More information

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.

Wentworth 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 information

csci 210: Data Structures Stacks and Queues

csci 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 information

Stacks and Queues. Chapter Stacks

Stacks and Queues. Chapter Stacks Chapter 18 Stacks and Queues 18.1 Stacks The stack abstract data type allows access to only one element the one most recently added. This location is referred to as the top of the stack. Consider how a

More information

== isn t always equal?

== 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 information

Plan for Week. What is a linear structure? Stacks Queues and Deques, Oh My!

Plan for Week. What is a linear structure? Stacks Queues and Deques, Oh My! Plan for Week What is a linear structure? Linear structures: Stack, Queue Ø Applications: LIFO, FIFO, other Ø Canonical examples and view to more Ø Java specifics of how to use these Friday: More examples

More information

Data Abstraction and Specification of ADTs

Data Abstraction and Specification of ADTs CITS2200 Data Structures and Algorithms Topic 4 Data Abstraction and Specification of ADTs Example The Reversal Problem and a non-adt solution Data abstraction Specifying ADTs Interfaces javadoc documentation

More information

Plan for Week. Linear structures: Stack, Queue. Friday: More examples of recursion and alternatives. Guide to using practice-it for APT-like problems

Plan for Week. Linear structures: Stack, Queue. Friday: More examples of recursion and alternatives. Guide to using practice-it for APT-like problems Plan for Week Linear structures: Stack, Queue Ø Applications: LIFO, FIFO, other Ø Canonical examples and view to more Ø Java specifics of how to use these Friday: More examples of recursion and alternatives

More information

Advanced Java Concepts Unit 3: Stacks and Queues

Advanced Java Concepts Unit 3: Stacks and Queues Advanced Java Concepts Unit 3: Stacks and Queues Stacks are linear collections in which access is completely restricted to just one end, called the top. Stacks adhere to a last-in, first-out protocol (LIFO).

More information

1 P age DS & OOPS / UNIT II

1 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 information

[2:3] Linked Lists, Stacks, Queues

[2:3] Linked Lists, Stacks, Queues [2:3] Linked Lists, Stacks, Queues Helpful Knowledge CS308 Abstract data structures vs concrete data types CS250 Memory management (stack) Pointers CS230 Modular Arithmetic !!!!! There s a lot of slides,

More information

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues

CPSC 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 information

Midterm Exam 2 CS 455, Spring 2014

Midterm Exam 2 CS 455, Spring 2014 Name: USC loginid (e.g., ttrojan): Midterm Exam 2 CS 455, Spring 2014 Monday, April 7, 2014 There are 6 problems on the exam, with 58 points total available. There are 7 pages to the exam, including this

More information

Name CPTR246 Spring '17 (100 total points) Exam 3

Name 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 information

LIFO : Last In First Out

LIFO : 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 information

final int a = 10; for(int i=0;i<a;i+=2) { for(int j=i;j<a;j++) { System.out.print("*"); } System.out.println(); }

final int a = 10; for(int i=0;i<a;i+=2) { for(int j=i;j<a;j++) { System.out.print(*); } System.out.println(); } CSCE 146 Exam 1 Review Part 1 Java Review This part went over the basics of Java, and the focus was mostly on arrays. There will be no questions that involve reading from and writing to files. Short Answer

More information

Queues. Data structures that wait their turn. queues 1

Queues. Data structures that wait their turn. queues 1 Queues Data structures that wait their turn queues 1 Queue characteristics FIFO: first in, first out insertion of items occurs at one end, removal occurs at the other end first item inserted is the first

More information

CS24 Week 4 Lecture 2

CS24 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 information

Stacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle.

Stacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle. Stacks 1 Stacks The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle. 2 Main stack operations Insertion and removal are defined by: push(e): inserts

More information

Lecture 2: Implementing ADTs

Lecture 2: Implementing ADTs Lecture 2: Implementing ADTs Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Discuss with your neighbors! From last lecture: - What is an ADT? - What is a data structure? From CSE

More information

STACKS AND QUEUES. Problem Solving with Computers-II

STACKS 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 information

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

CPSC 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 information

CSC148H Week 3. Sadia Sharmin. May 24, /20

CSC148H Week 3. Sadia Sharmin. May 24, /20 CSC148H Week 3 Sadia Sharmin May 24, 2017 1/20 Client vs. Developer I For the first couple of weeks, we have played the role of class designer I However, you are also often in the opposite role: when a

More information

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO) Outline stacks stack ADT method signatures array stack implementation linked stack implementation stack applications infix, prefix, and postfix expressions 1 Stacks stacks of dishes or trays in a cafeteria

More information

CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh University of Toronto Scarborough

CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh University of Toronto Scarborough CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists Marzieh Ahmadzadeh University of Toronto Scarborough Administrative Detail All practicals are up on course website. Term test # 1 and #2 schedule

More information

Stacks and Queues. David Greenstein Monta Vista

Stacks and Queues. David Greenstein Monta Vista Stacks and Queues David Greenstein Monta Vista Stack vs Queue Stacks and queues are used for temporary storage, but in different situations Stacks are Used for handling nested structures: processing directories

More information

CSCE 2014 Final Exam Spring Version A

CSCE 2014 Final Exam Spring Version A CSCE 2014 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers

More information

Lecture 2: Stacks and Queues

Lecture 2: Stacks and Queues Lecture 2: Stacks and Queues CSE 373: Data Structures and Algorithms CSE 373 19 WI - KASEY CHAMPION 1 Warm Up 1. Grab a worksheet 2. Introduce yourself to your neighbors J 3. Discuss the answers 4. Log

More information

COSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor

COSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor COSC160: Data Structures: Lists and Queues Jeremy Bolton, PhD Assistant Teaching Professor Outline I. Queues I. FIFO Queues I. Usage II. Implementations II. LIFO Queues (Stacks) I. Usage II. Implementations

More information

Object Oriented Programming and Design in Java. Session 19 Instructor: Bert Huang

Object Oriented Programming and Design in Java. Session 19 Instructor: Bert Huang Object Oriented Programming and Design in Java Session 19 Instructor: Bert Huang Announcements Homework 4 due MONDAY. Apr. 19 No multithreading in programming part Review Deadlocks and the Dining Philosophers

More information

Basic Data Structures

Basic 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 information

Interfaces & Generics

Interfaces & Generics Interfaces & Generics CSC207 Winter 2018 The Programming Interface The "user" for almost all code is a programmer. That user wants to know:... what kinds of object your class represents... what actions

More information

Basic Data Structures 1 / 24

Basic 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 information

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

Discussion 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 information

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1 CMSC 341 Linked Lists, Stacks and Queues CMSC 341 Lists, Stacks &Queues 1 Goal of the Lecture To complete iterator implementation for ArrayList Briefly talk about implementing a LinkedList Introduce special

More information

Abstract Data Types 1

Abstract 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 information

CSE 373. Java Collection Framework. reading: Weiss Ch. 3, 4.8. slides created by Marty Stepp

CSE 373. Java Collection Framework. reading: Weiss Ch. 3, 4.8. slides created by Marty Stepp CSE 373 Java Collection Framework reading: Weiss Ch. 3, 4.8 slides created by Marty Stepp http://www.cs.washington.edu/373/ 1 Arrays array: An object that stores many values of the same type. element:

More information

cs Java: lecture #6

cs Java: lecture #6 cs3101-003 Java: lecture #6 news: homework #5 due today little quiz today it s the last class! please return any textbooks you borrowed from me today s topics: interfaces recursion data structures threads

More information

More Data Structures (Part 1) Stacks

More Data Structures (Part 1) Stacks More Data Structures (Part 1) Stacks 1 Stack examples of stacks 2 Top of Stack top of the stack 3 Stack Operations classically, stacks only support two operations 1. push 2. pop add to the top of the stack

More information

Priority Queue ADT. Revised based on textbook author s notes.

Priority 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 information

CMSC Introduction to Algorithms Spring 2012 Lecture 7

CMSC 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 information

Stacks and Queues. Gregory D. Weber. CSCI C243 Data Structures

Stacks and Queues. Gregory D. Weber. CSCI C243 Data Structures Stacks and Queues Gregory D. Weber CSCI C243 Data Structures Principal Points 1. The Stack interface: how to declare it, what it does. 2. Generics: why they were added to Java, how to use them. 3. The

More information

Adam Blank Lecture 5 Winter 2015 CSE 143. Computer Programming II

Adam Blank Lecture 5 Winter 2015 CSE 143. Computer Programming II Adam Blank Lecture 5 Winter 2015 CSE 143 Computer Programming II CSE 143: Computer Programming II Stacks & Queues Questions From Last Time 1 Can we include implementation details in the inside comments

More information

CS6202 - 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 information

-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed "stack method of expression evaluation" in 1955.

-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed stack method of expression evaluation in 1955. Topic 15 Implementing and Using "stack n. The set of things a person has to do in the future. "I haven't done it yet because every time I pop my stack something new gets pushed." If you are interrupted

More information

C Sc 227 Practice Test 2 Section Leader Your Name 100pts. a. 1D array b. PriorityList<E> c. ArrayPriorityList<E>

C Sc 227 Practice Test 2 Section Leader Your Name 100pts. a. 1D array b. PriorityList<E> c. ArrayPriorityList<E> C Sc 227 Practice Test 2 Section Leader Your Name 100pts 1. Approximately how many lectures remain in C Sc 227 (give or take 2)? (2pts) 2. Determine the tightest upper bound runtimes of the following loops.

More information

CSE 332: Data Structures. Spring 2016 Richard Anderson Lecture 1

CSE 332: Data Structures. Spring 2016 Richard Anderson Lecture 1 CSE 332: Data Structures Spring 2016 Richard Anderson Lecture 1 CSE 332 Team Instructors: Richard Anderson anderson at cs TAs: Hunter Zahn, Andrew Li hzahn93 at cs lia4 at cs 2 Today s Outline Introductions

More information

Introduction to Software Design

Introduction to Software Design CSI 1102 1 Abdulmotaleb El Saddik University of Ottawa School of Information Technology and Engineering (SITE) Multimedia Communications Research Laboratory (MCRLab) Distributed Collaborative Virtual Environments

More information

Abstract 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 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 information

Stacks. Revised based on textbook author s notes.

Stacks. Revised based on textbook author s notes. Stacks Revised based on textbook author s notes. Stacks A restricted access container that stores a linear collection. Very common for solving problems in computer science. Provides a last-in first-out

More information

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University Lecture 6 COMP1006/1406 (the OOP course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments A1,A2,A3 are all marked A4 marking just started A5 is due Friday, A6 is due Monday a quick

More information

CIS Fall Data Structures Midterm exam 10/16/2012

CIS Fall Data Structures Midterm exam 10/16/2012 CIS 2168 2012 Fall Data Structures Midterm exam 10/16/2012 Name: Problem 1 (30 points) 1. Suppose we have an array implementation of the stack class, with ten items in the stack stored at data[0] through

More information

Abstract Data Types 1

Abstract 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 information

CSE 326 Team. Today s Outline. Course Information. Instructor: Steve Seitz. Winter Lecture 1. Introductions. Web page:

CSE 326 Team. Today s Outline. Course Information. Instructor: Steve Seitz. Winter Lecture 1. Introductions. Web page: CSE 326 Team CSE 326: Data Structures Instructor: Steve Seitz TAs: Winter 2009 Steve Seitz Lecture 1 Eric McCambridge Brent Sandona Soyoung Shin Josh Barr 2 Today s Outline Introductions Administrative

More information

Lists. CSC212 Lecture 8 D. Thiebaut, Fall 2014

Lists. CSC212 Lecture 8 D. Thiebaut, Fall 2014 Lists CSC212 Lecture 8 D. Thiebaut, Fall 2014 Review List = Organization of Data in a Linear Fashion, where Order is Important Set of actions that can be carried out efficiently on the data. Typical Actions

More information

Queues Fall 2018 Margaret Reid-Miller

Queues 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 information

Day 6. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 6. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 6 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments Assignment 3 is due on Monday a quick look back abstract classes and interfaces casting objects abstract data

More information

15. Stacks and Queues

15. Stacks and Queues COMP1917 15s2 15. Stacks and Queues 1 COMP1917: Computing 1 15. Stacks and Queues Reading: Moffat, Section 10.1-10.2 Overview Stacks Queues Adding to the Tail of a List Efficiency Issues Queue Structure

More information

CS 455 MT 2 Sample Questions

CS 455 MT 2 Sample Questions CS 455 MT 2 Sample Questions [CS455 Bono] This doesn t cover everything. There s likely to be at least one question about exceptions (e.g., writing some code with exceptions, or saying what some code does

More information

CSc 120. Introduction to Computer Programming II. 14: Stacks and Queues. Adapted from slides by Dr. Saumya Debray

CSc 120. Introduction to Computer Programming II. 14: Stacks and Queues. Adapted from slides by Dr. Saumya Debray CSc 120 Introduction to Computer Programming II Adapted from slides by Dr. Saumya Debray 14: Stacks and Queues linear data structures 2 Linear data structures A linear data structure is a collec6on of

More information

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013 Linear Structure Linear Structures Chapter 4 CPTR 318 Every non-empty linear structure has A unique element called first A unique element called last Every element except last has a unique successor Every

More information

.:: UNIT 4 ::. STACK AND QUEUE

.:: 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 information

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10

Keeping 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 information

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013 Linear Structure Linear Structures Chapter 4 CPTR 318 Every non-empty linear structure has A unique element called first A unique element called last Every element except last has a unique successor Every

More information

Name: After line 1: After line 3: After line 5: After line 8: After line 11:

Name: After line 1: After line 3: After line 5: After line 8: After line 11: 1. (5 points) Determine the stack contents at the points indicated below during the following operations on the stack ADT. Write down the stack contents after the operation on the given line is executed.

More information

ECE Spring 2018 Problem Set #0 Due: 1/30/18

ECE Spring 2018 Problem Set #0 Due: 1/30/18 ECE 45234 - Spring 2018 Problem Set #0 Due: 1/30/18 The purpose of this first problem set is to remind you of the material you need from 2574 and help get you up-to-speed with python. This course uses

More information

MIDTERM WEEK - 9. Question 1 : Implement a MyQueue class which implements a queue using two stacks.

MIDTERM WEEK - 9. Question 1 : Implement a MyQueue class which implements a queue using two stacks. Ashish Jamuda Week 9 CS 331-DATA STRUCTURES & ALGORITHMS MIDTERM WEEK - 9 Question 1 : Implement a MyQueue class which implements a queue using two stacks. Solution: Since the major difference between

More information

Stacks Goodrich, Tamassia, Goldwasser Stacks

Stacks Goodrich, Tamassia, Goldwasser Stacks Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Stacks Stacks 1 The Stack ADT The Stack ADT

More information

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology

Lists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology Lists and Iterators CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology Announcements Should be making progress on VectorGraphics. Should have turned in CRC cards,

More information

Data Structures And Algorithms

Data Structures And Algorithms Data Structures And Algorithms Stacks Eng. Anis Nazer First Semester 2017-2018 Stack An Abstract data type (ADT) Accessed only on one end Similar to a stack of dishes you can add/remove on top of stack

More information

Examination Questions Midterm 1

Examination Questions Midterm 1 CS1102s Data Structures and Algorithms 10/2/2010 Examination Questions Midterm 1 This examination question booklet has 9 pages, including this cover page, and contains 15 questions. You have 40 minutes

More information

Chapter 9 STACK, QUEUE

Chapter 9 STACK, QUEUE Chapter 9 STACK, QUEUE 1 LIFO: Last In, First Out. Stacks Restricted form of list: Insert and remove only at front of list. Notation: Insert: PUSH Remove: POP The accessible element is called TOP. Stack

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard 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 information

PA3 Design Specification

PA3 Design Specification PA3 Teaching Data Structure 1. System Description The Data Structure Web application is written in JavaScript and HTML5. It has been divided into 9 pages: Singly linked page, Stack page, Postfix expression

More information

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

ADVANCED 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 information

CSC 321: Data Structures. Fall 2012

CSC 321: Data Structures. Fall 2012 CSC 321: Data Structures Fall 2012 Lists, stacks & queues Collection classes: List (ArrayList, LinkedList), Set (TreeSet, HashSet), Map (TreeMap, HashMap) ArrayList performance and implementation LinkedList

More information

Data Structure. Recitation VII

Data 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 information

Directed Acyclic Graphs & Topological Sort

Directed Acyclic Graphs & Topological Sort Directed Acyclic Graphs & Topological Sort CS6: Introduction to Data Structures & Algorithms Spring 08 Outline Directed Acyclic Graphs Topological Sort Hand-simulation Pseudo-code Runtime analysis 4 Directed

More information

CMPSCI 187: Programming With Data Structures. Review for Final Exam David Mix Barrington 10 December 2012

CMPSCI 187: Programming With Data Structures. Review for Final Exam David Mix Barrington 10 December 2012 CMPSCI 187: Programming With Data Structures Review for Final Exam David Mix Barrington 10 December 2012 Exam Overview Thursday 13 December, 1:30-3:30 p.m., Marcus 131 Format is the same as the Fall 2011

More information

16-Dec-10. Collections & Data Structures ABSTRACTION VS. IMPLEMENTATION. Abstraction vs. Implementation

16-Dec-10. Collections & Data Structures ABSTRACTION VS. IMPLEMENTATION. Abstraction vs. Implementation Collections & Data Structures Boaz Kantor Introduction to Computer Science IDC Herzliya ABSTRACTION VS. IMPLEMENTATION 2 Abstraction vs. Implementation Data structures provide both abstraction and implementation.

More information

1.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: 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 information

Since it is an interface, we need a concrete class during its declaration. There are many ways to initialize a Queue object, most common being-

Since it is an interface, we need a concrete class during its declaration. There are many ways to initialize a Queue object, most common being- Laboratory 2 Data Structures-II Implementation of Daa structures using Collection frame work Obecjective Data Structures. A data structure is a particular way of storing and organizing data in a computer

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

! 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 information

12 Abstract Data Types

12 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 information

1. Introduction. Lecture Content

1. 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

CS200 Spring 2004 Midterm Exam II April 14, Value Points a. 5 3b. 16 3c. 8 3d Total 100

CS200 Spring 2004 Midterm Exam II April 14, Value Points a. 5 3b. 16 3c. 8 3d Total 100 CS200 Spring 2004 Midterm Exam II April 14, 2004 Value Points 1. 12 2. 26 3a. 5 3b. 16 3c. 8 3d. 8 4. 25 Total 100 Name StudentID# 1. [12 pts] Short Answer from recitations: a) [3 pts] What is the first

More information

Name: 1 stack<int> s; 2 s.push(9) 3 s.push(5) 4 s.push(10) 5 s.push(1) 6 s.pop() 7 s.pop() 8 s.push(0) 9 s.pop() 10 s.pop() 11 s.

Name: 1 stack<int> s; 2 s.push(9) 3 s.push(5) 4 s.push(10) 5 s.push(1) 6 s.pop() 7 s.pop() 8 s.push(0) 9 s.pop() 10 s.pop() 11 s. 1. (5 points) Determine the stack contents at the points indicated below during the following operations on the stack ADT. Write down the stack contents after the operation on the given line is executed.

More information

Stacks Fall 2018 Margaret Reid-Miller

Stacks Fall 2018 Margaret Reid-Miller Stacks 15-121 Fall 2018 Margaret Reid-Miller Today Exam 2 is next Tuesday, October 30 Today: Quiz 5 solutions Recursive add from last week (see SinglyLinkedListR.java) Stacks ADT (Queues on Thursday) ArrayStack

More information

CMPSCI 187: Programming With Data Structures. Review for First Midterm 9 October 2011

CMPSCI 187: Programming With Data Structures. Review for First Midterm 9 October 2011 CMPSCI 187: Programming With Data Structures Review for First Midterm 9 October 2011 Format Two hours, closed-book, no calculators, computers, etc. Question types as on practice exam: Java Concepts (10

More information

Stacks and Queues. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG

Stacks and Queues. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Stacks and Queues EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG What is a Stack? A stack is a collection of objects. Objects in a stack are inserted and removed according to the

More information

Points off Total off Net Score. CS 314 Final Exam Spring 2016

Points off Total off Net Score. CS 314 Final Exam Spring 2016 Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2016 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.

More information

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017 Name: USC NetID (e.g., ttrojan): CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017 There are 6 problems on the exam, with 62 points total available. There are 10 pages to the exam (5 pages double-sided),

More information