CS2852 Week 3, Class 2 Today Stacks Queues SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.

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, 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, Queues, and Deques
Stacks, Queues, and Deques
Building Java Programs
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Problem of the Day  What do you get when you cross a mountain climber and a grape?
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
The Java Collections Framework (JCF) Introduction and review 1.
Today TBA Tomorrow Good Friday SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 5, Class 3.
CSC 212 Stacks & Queues. Announcement Many programs not compiled before submission  Several could not be compiled  Several others not tested with javadoc.
Stacks and Queues Pepper. Why History Simplicity Operating Systems – Function Call Stack.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
CS2852 Week 2, Class 1 Today Generics (Section 051) Big-O runtime analysis Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See.
CS-2852 Data Structures Week 10, Class 1 Lab 8 notes Big-O revisited CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
Today Quiz Multithreading Options Qt socket buffers between threads Quiz today & Tuesday in lab SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr.
CS2910 Week 1, Class 2 Today Announce Prof. Michael Vieau’s S-341 6p Thurs Wk 2 Assignment for tomorrow Data Encoding, Part 1 Parsing Data Muddiest Point.
CS2910 Week 1, Class 1 Today Introductions Class/Lab Layout Safety Review - Note about Lab Safety Review Announce Prof. Michael Vieau’s S-341 6p Thurs.
CS-2852 Data Structures Week 5, Class 1 – Testing and Stacks Return Exams & Labs  Package-level access  UML connectors for instance variables Announcement:
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
CS-2852 Data Structures Week 5, Class 2 – Testing and Stacks Announcement: Lab Demos - 2/3 & 4 on Friday Testing  Definitions, Example  (tentative) Testing.
Today C/C++:.h/.cpp; compiling and linking Fourier Transform (corrected) Nyquist Theorem Audio sampling rates SE-2811 Slide design: Dr. Mark L. Hornick.
CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
Today Nervous System Response Time SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 3, Class 2.
CS-2852 Data Structures Week 10, Class 3 Final Announcement re. Final Choosing a Data Structure (Concluded) Poll Everywhere Survey & Results Conclusion.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
CS2852 Week 6, Class 1 Today The run-time stack Writing and proving recursive methods SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 5, Class 2 Today Queue Applications Circular Queue Implementation Testing SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 7, Class 1 Today Binary Search Tree Implementing add Implementing find Return Quiz 4 (second attempt) Both sections are graded SE-2811 Slide.
CS2852 Week 6, Class 2 Today Class exercise: Implementing a recursive method Binary Search Trees Tomorrow: Quiz at start of lab Implementing a recursive.
Today Return Quiz First true release of final project (Lab 8) Multithreading Options Qt socket buffers between threads SE-2811 Slide design: Dr. Mark L.
CS-2852 Data Structures Week 10, Class 2 Announcement re. Final Choosing a Data Structure CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
CS2852 Week 3, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
CS2852 Week 2, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
Week 7, Class 1: The Command Pattern (cont.) Get Ready for Poll Everywhere Labs 2 & 3 returned Lab 7 due this evening at 11pm Quiz tomorrow at start of.
CS2910 Week 8, Class 2 Today Return Quiz Look at Schedule TCP implementation! Week 8, Monday Quiz on SMTP May include some questions requiring you to interpret.
CS-2851 Dr. Mark L. Hornick 1 Stacks and Queues Behavior vs. Structure.
CS2910 Week 7, Class 1 Today Capturing SMTP with Thunderbird Tomorrow Extra office hour at 11 am (right after lab) Friday Office hour cancelled SE-2811.
CS-2852 Data Structures Week 4, Class 1 - Review Review! Thursday Exam I - Review Implementing ArrayList Big-O Iterators – High-level description Linked.
Click to edit Master text styles Stacks Data Structure.
CS2910 Week 6, Lab Today Dictionaries in Python SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
SE3910 Week 8, Class 2 Week 4 Lab: Please return your graded Lab 4 to me so I can enter it in my gradebook Week 7, Class 2 (Wednesday) Half-Exam 2 Done.
CS-2852 Data Structures Week 5, Class 3 – Testing and Recursion Queue Implementing finite queues Binary Search Recursion Tomorrow – Quiz, Lab demos, Lab.
Stacks and Queues. 2 Abstract Data Types (ADTs) abstract data type (ADT): A specification of a collection of data and the operations that can be performed.
QueueStack CS1020.
Slide style: Dr. Hornick
CSE 116/504 – Intro. To Computer Science for Majors II
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Building Java Programs
Week 7, Class 1: The Command Pattern (cont.)
CSE 214 – Computer Science II Stacks
Stacks and Queues CLRS, Section 10.1.
Slide design: Dr. Mark L. Hornick
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
SE-1021 Software Engineering II
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Week 8, Class 3: Model-View-Controller
CS-2852 Data Structures Week 1, Class 1 Data Structures Syllabus
Slide design: Dr. Mark L. Hornick
Stacks, Queues, and Deques
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Stacks and Queues.
Presentation transcript:

CS2852 Week 3, Class 2 Today Stacks Queues SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1

Stacks Like a stack of dishes Like a PEZ dispenser Last In, First Out (LIFO) 815_1.jpg?v=8CF3A2E27D55BD0 SE-2811 Dr.Yoder 2

A stack interface public interface Stack { E pop(); void push(E element); E peek(); boolean isEmpty(); } (Not in Java API – see code examples) SE-2811 Dr.Yoder 3

Why Stacks? Simple to use Many applications don’t need more Avoid “breaking the rules” accidentally The main advantage of a Stack is that it causes compiler errors. SE-2811 Dr.Yoder 4

Implementing a Stack With ArrayList: push: add(E) pop: remove(n-1) peek: [EXERCISE!] isEmpty: isEmpty() To extend, or to compose? SE-2811 Dr.Yoder 5

To extend, or to compose? Exercise: 1. Which protects us from “accidentally” sticking something at the bottom of the stack, ExtendsArrayStack or WrapsArrayStack? 2. Do you personally like ExtendsArrayStack or WrapsArrayStack better? Why? SE-2811 Dr.Yoder 6

Queues Like a British queue A line at the grocery store A line at the movie theatre etc. First In, First Out (FIFO) the-front-of-the-queue SE-2811 Dr.Yoder 7

A queue interface public interface Queue { E poll(); void offer(E element); E peek(); boolean isEmpty(); } (Not in Java API – see code examples) SE-2811 Dr.Yoder 8

Why Queues? Simple to use Many applications don’t need more Avoid “breaking the rules” accidentally The main advantage of a Queue is that it causes compiler errors. SE-2811 Dr.Yoder 9

Implementing a Queue With Java’s ArrayList: push: add(0,E) – EXERCISE: What is the Big-O? pop: remove(n-1) – EXERCISE: Big-O? peek: [EXERCISE!] – EXERCISE: Big-O? isEmpty: isEmpty() With Java’s LinkedList: push: add(0,E) – EXERCISE: What is the Big-O? pop: remove(n-1) – EXERCISE: Big-O? peek: [EXERCISE!] – EXERCISE: Big-O? isEmpty: isEmpty() SE-2811 Dr.Yoder 10

Two methods for each operation: One throws exceptions if nothing there The other returns null Java’s Queue Interface SE-2811 Dr.Yoder 11 Throws exception Returns special value Insertadd(e)offer(e) Removeremove()poll() Examineelement()peek()

Exercise: Which to use? What are the advantages of using the method that throws an exception? What are the advantages of using the method that returns null? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 12

Muddiest Point Wait for the slides, or follow this link to answer both questions at once: SE-2811 Dr.Yoder 13

SE-2811 Dr. Josiah Yoder 14

SE-2811 Dr. Josiah Yoder 15