ITEC200 Week05 Stacks. www.ics.mq.edu.au/ppdp 2 Learning Objectives – Week05 Stacks (Chapter05) Students can Use the methods provided in the public interface.

Slides:



Advertisements
Similar presentations
ITEC200 Week04 Lists and the Collection Interface.
Advertisements

ITEC200 Week10 Sorting. pdp 2 Learning Objectives – Week10 Sorting (Chapter10) By working through this chapter, students should: Learn.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Joseph Lindo Abstract Data Types Sir Joseph Lindo University of the Cordilleras.
COMPSCI 105 S Principles of Computer Science 13 Stacks.
Stacks Chapter 5. Chapter Objectives  To learn about the stack data type and how to use its four methods: push, pop, peek, and empty  To understand.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
ITEC200 – Week08 Trees. 2 Chapter Objectives Students can: Describe the Tree abstract data type and use tree terminology such as.
ITEC200 – Week03 Inheritance and Class Hierarchies.
ITEC200 – Week07 Recursion. 2 Learning Objectives – Week07 Recursion (Ch 07) Students can: Design recursive algorithms to solve.
ITEC200 Week01 Introduction to Software Design.
ITEC200 Week02 Program Correctness and Efficiency.
ITEC200 Week06 Queues. 2 Learning Objectives – Week06 Queues (Ch6) Students can Manage data using the queue Abstract Data Type.
ITEC200 Week 11 Self-Balancing Search Trees. 2 Learning Objectives Week 11 (ch 11) To understand the impact that balance has on.
Chapter 3 Stacks.
CHAPTER 3 Stacks. Chapter Objectives  To learn about the stack data type and how to use its four methods:  push  pop  peek  empty  To understand.
Stacks Chapter 5. Chapter 5: Stacks2 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop, peek, and empty.
Sets and Maps ITEC200 – Week Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn.
Stacks Chapter 5. Chapter 5: Stacks2 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop, peek, and empty.
© 2006 Pearson Addison-Wesley. All rights reserved7 B-1 Chapter 7 (continued) Stacks.
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks.
Fall 2007CS 2251 Stacks Chapter 5. Fall 2007CS 2252 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop,
Fall 2007CS 2251 Stacks Chapter 5. Fall 2007CS 2252 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop,
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
TCSS 342, Winter 2005 Lecture Notes
Algorithms and Data Structures Representing Sequences by Arrays and Linked Lists.
More About Stacks: Stack Applications Dan Nguyen CS 146, Spring 2004 Professor Sin-Min Lee.
Definition Stack is an ordered collection of data items in which access is possible only at one end (called the top of the stack). Stacks are known.
Chapter 3 Stacks.
CHAPTER 3 Stacks MIDTERM OCTOBER 17 IN LAB. Chapter Objectives  To learn about the stack data type and how to use its four methods:  push  pop  peek.
COMP 121 Week 14: Queues. Objectives Learn how to represent a queue Learn how to use the methods in the Queue interface Understand how to implement the.
Chapter 7 Stack. Overview ● The stack data structure uses an underlying linear storage organization.  The stack is one of the most ubiquitous data structures.
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks (and a bit of generics for flavor)
Stack Data Structure By : Imam M Shofi. What is stack? A stack is a limited version of an array. A stack is a limited version of an array. New elements,
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
Lecture Objectives To understand how Java implements a stack To learn how to implement a stack using an underlying array or linked list Implement a simple.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
COMP 121 Week 13: Stacks. Objectives Learn about the stack data type and how to use its four methods: push, pop, peek, and empty Understand how Java implements.
Chapter 7 Stacks. © 2004 Pearson Addison-Wesley. All rights reserved 7-2 The Abstract Data Type: Developing an ADT During the Design of a Solution Specifications.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
Lecture objectives  Collections interface  Learn about stacks and their methods:  push  pop  peek  Empty  Analyze stack applications and why stacks.
CSE 373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
Queues Chapter 6. Chapter 6: Queues Chapter Objectives To learn how to represent a waiting line (queue) and how to use the five methods in the Queue interface:
Lecture Objectives  To understand how Java implements a stack  To learn how to implement a stack using an underlying array or linked list  Implement.
April 27, 2017 COSC Data Structures I Review & Final Exam
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
Prefix notation in action
Stacks Chapter 5.
Stacks Chapter 6.
MIDTERM OCTOBER 17 IN LAB Chapter 3 Stacks.
Revised based on textbook author’s notes.
MEMORY REPRESENTATION OF STACKS
CSE 373: Data Structures and Algorithms
Copyright ©2012 by Pearson Education, Inc. All rights reserved
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
PART II STACK APPLICATIONS
Chapter 5 Stacks.
Stacks Chapter 5 Adapted from Pearson Education, Inc.
MIDTERM OCTOBER 11 IN LAB Chapter 3 Stacks.
Chapter 7 Stack.
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.
Stacks.
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

ITEC200 Week05 Stacks

2 Learning Objectives – Week05 Stacks (Chapter05) Students can Use the methods provided in the public interface of the stack data type to manage a stack (push, pop, peek, and empty) Explain how Java implements stacks Analyse and augment various stack implementations (List, array, linked list) Identify problems requiring stacks and provide appropriate solutions Explain how detecting palindromes, testing for balanced (properly nested) parentheses, and evaluating arithmetic expressions (postfix and infix) can be accomplished using stacks and augment existing programs to perform related tasks

3 Stack Abstract Data Type A stack can be compared to a Pez dispenser –Only the top item can be accessed –Can only extract one item at a time A stack is a data structure with the property that only the top element of the stack is accessible The stack’s storage policy is Last-In, First-Out

4 Specification of the Stack Abstract Data Type

5 Stack Application Example 1: Palindrome Finder Palindrome: string that reads the same in either direction, Such as: “I saw I was I”

6 Stack Application Example 2: Parentheses Matcher When analyzing arithmetic expressions, it is important to determine whether an expression is balanced with respect to parentheses –(a+b*(c/(d-e)))+(d/e)

7 Algorithm for Balanced Parenthesis Checking

8 Implementing a Stack as an Extension of Vector The Java API includes a Stack class as part of the package java.util The Stack class is implemented as an Extension of the Vector class. The Vector class is a List that houses a growable array of objects s =

9 Implementing a Stack with a List Component Can use either the ArrayList, Vector, or the LinkedList classes as all implement the List interface Name of class illustrated in text is ListStack –ListStack is an adapter class as it adapts the methods available in another class to the interface its clients expect by giving different names to essentially the same operations

10 Implementing a Stack Using an Array

11 Implementing a Stack as a Linked Data Structure We can implement a stack using a linked list of nodes

12 Comparison of Stack Implementations Extending a Vector (as is done by Java) is a poor choice for stack implementation as all Vector methods are accessible Easiest implementation would be to use an ArrayList component for storing data All insertions and deletions are constant time regardless of the type of implementation discussed

13 Additional Stack Applications Two case studies that consider the application of stacks in depth: –Evaluating postfix arithmetic expressions E.g., 4 7 * 20 – = 8) –Converting arithmetic expressions from infix to postfix E.g., ( 4 * 7 ) – 20 converts to 4 7 * 20 –

14 Case Study I: Evaluating Postfix Expressions

15 Evaluating Postfix Expressions (continued)

16 Evaluating Postfix Expressions (continued)

17 Evaluating Postfix Expressions (continued)

18 Case Study II: Converting Infix to Postfix Converting from Infix to Postfix facilitates the evaluation of infix expressions by arithmetic computational devices w – 5.1 / sum * 2w 5.1 sum / 2 * – Infix Postfix

19 Converting Infix to Postfix (continued)

20 Converting from Infix to Postfix (continued)

21 Converting from Infix to Postfix (continued)

22 Converting from Infix to Postfix (continued)

23 Where to from here… Work through Chapter 5 of the Koffman & Wolfgang Text Conceptual Questions and Practical Exercises Submit all preliminary work Be prompt for your online class

24 Acknowledgements These slides were based upon the Objects, Abstraction, Data Structures and Design using Java Version 5.0 Chapter 35PowerPoint presentation by Elliot B. Koffman and Paul A. T. Wolfgang