Stacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks

Size: px
Start display at page:

Download "Stacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks"

Transcription

1 Stacks Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks

2 Stacks: Definitions and Operations A LIFO list: Last In, First Out. Restricted form of list: Insert/Remove only at front or TOP of list. Accessible Element: TOP Data Structures 2 Stacks

3 Stack Operations Create/Delete IsFull()/IsEmpty() Push (Insert), Pop (remove) TopValue() Stack Implementations Array Based. Linked List Based. Data Structures 3 Stacks

4 Array-Based Stack top D top A C B A top E B A top F A push (A) push (B) push (C) push (D) pop () pop () push (E) pop () pop () push (F) top pop () pop () Data Structures 4 Stacks

5 Stack Interface / Stack ADT / public interface Stack<E> { / R e i n i t i a l i z e the stack. The user i s responsible f o r e c l a i m i n g the storage used by the stack elements. public void c l e a r ( ) ; / Push an element onto the top of the stack. p u b l i c void push (E i t ) ; / Remove and r e t u r n the element at the top of the sta p u b l i c E pop ( ) ; A copy of the top element. / public E topvalue ( ) ; The number of elements i n the stack. / public i n t l e n g t h ( ) ; Data Structures 5 Stacks

6 Array-Based Stack / Array based stack implementation / class AStack<E> implements Stack<E> { private s t a t i c f i n a l i n t d e f a u l t S i z e = 10; private i n t maxsize ; / / Maximum size of stack private i n t top ; / / Index f o r top Object private E [ ] l i s t A r r a y ; / / Array holding stack / / Constructors AStack ( ) { this ( d e f a u l t S i z e ) ; AStack ( i n t size ) { maxsize = size ; top = 0; l i s t A r r a y = (E [ ] ) new Object [ size ] ; / / Create l i s t A r r a y Data Structures 6 Stacks

7 Array-Based Stack public void c l e a r ( ) / / R e i n i t i a l i z e stack { top = 0; public void push (E i t ) { / / Push i t onto stack a s s e r t top!= maxsize : Stack i s f u l l ; l i s t A r r a y [ top ++] = i t ; public E pop ( ) { / / Pop top element a s s e r t top!= 0 : Stack i s empty ; return l i s t A r r a y [ top ] ; public E topvalue ( ) { / / Return t o p element a s s e r t top!= 0 : Stack i s empty ; return l i s t A r r a y [ top 1]; public i n t l e n g t h ( ) { return top ; / / Return l e n g t h Data Structures 7 Stacks

8 Linked Stacks A simplified version of the linked list, where insertions/deletions are only through the head of the list. Freelist implementation is an example. No header node is used. Data Structures 8 Stacks

9 Linked Stack Implementation class LStack<E> implements Stack<E> { private Link<E> top ; / / P o i n t e r to f i r s t element private i n t size ; / / Number of elements / / Constructors public LStack ( ) { top = null ; s ize = 0; public LStack ( i n t sz ) { top = null ; s ize = 0; / / R e i n i t i a l i z e stack public void c l e a r ( ) { top = null ; s ize = 0; public void push (E i t ) { / / Put i t on stack top = new Link<E>( i t, top ) ; size ++; Data Structures 9 Stacks

10 Linked Stack Implementation public E pop ( ) { / / Remove i t from stack a s s e r t top!= null : Stack i s empty ; E i t = top. element ( ) ; top = top. next ( ) ; size ; return i t ; public E topvalue ( ) { / / Return top value a s s e r t top!= null : Stack i s empty ; return top. element ( ) ; public i n t l e n g t h ( ) { return size ; / / Return l e n g t h Data Structures 10 Stacks

11 Stack Application:Expression Evaluation Infix to Postfix Conversion A + B C D E // Infix Form ABC DE + // Postfix Form Evaluation of expressions in postfix form. Data Structures 11 Stacks

12 Stack Application:Recursion Subroutine calls need to preserve return addresses, parameters and local variables. Implemented using a program stack. Data Structures 12 Stacks

13 Stack Application:Infix To Postfix I n i t i a l i z e the stack. / / stack i s empty for ( each operator or operand i n the i n p u t expression ) { i f ( an operand ) add to P o s t x expression else i f ( an operator ) { i f ( stack i s empty ) push oper. i n t o stack else { while ( i n p u t oper. prec. < than stack top oper. prec ) { pop operator from stack, add to P o s t f i x expression i f stack i s empty, break / / out of the loop push i n p u t oper. i n t o stack while ( stack i s not empty ) { pop the stack ; add operator to P o s t x expression % Data Structures 13 Stacks

14 Stack Application:Postfix Expression Evaluation I n i t i a l i z e the stack. / / stack i s empty for ( each operator or operand i n the i n p u t expression ){ i f ( an operand ) push i n t o stack else i f ( an operator ) { opnd2 = pop stack opnd1 = pop stack r e s u l t = Evaluate opnd1 oper opnd2 push r e s u l t onto stack r e s u l t = pop stack Data Structures 14 Stacks

Lecture 4: Stacks and Queues

Lecture 4: Stacks and Queues Reading materials Goodrich, Tamassia, Goldwasser (6th), chapter 6 OpenDSA (https://opendsa-server.cs.vt.edu/odsa/books/everything/html/): chapter 9.8-13 Contents 1 Stacks ADT 2 1.1 Example: CharStack ADT

More information

EENG/INFE 212 Stacks

EENG/INFE 212 Stacks EENG/INFE 212 Stacks A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted at one end called the top of the stack. A stack is a dynamic constantly

More information

MIT Loop Optimizations. Martin Rinard

MIT Loop Optimizations. Martin Rinard MIT 6.035 Loop Optimizations Martin Rinard Loop Optimizations Important because lots of computation occurs in loops We will study two optimizations Loop-invariant code motion Induction variable elimination

More information

Lists, Stacks, and Queues (plus Priority Queues)

Lists, Stacks, and Queues (plus Priority Queues) Lists, Stacks, and Queues (plus Priority Queues) The structures lists, stacks, and queues are composed of similar elements with different operations. Likewise, with mathematics: (Z, +, 0) vs. (Z,, 1) List

More information

Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION

Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science Identification

More information

Data Structures and Algorithms Winter Semester

Data Structures and Algorithms Winter Semester Page 0 German University in Cairo December 26, 2015 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher Dr. Wael Abouelsadaat Data Structures and Algorithms Winter Semester 2015-2016 Final

More information

Computing Static Single Assignment (SSA) Form

Computing Static Single Assignment (SSA) Form Computing Static Single Assignment (SSA) Form Overview What is SSA? Advantages of SSA over use-def chains Flavors of SSA Dominance frontiers revisited Inserting φ-nodes Renaming the variables Translating

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 12

CMSC 132, Object-Oriented Programming II Summer Lecture 12 CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 12 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 12.1 Trees

More information

Solution suggestions for examination of Logic, Algorithms and Data Structures,

Solution suggestions for examination of Logic, Algorithms and Data Structures, Department of VT12 Software Engineering and Managment DIT725 (TIG023) Göteborg University, Chalmers 24/5-12 Solution suggestions for examination of Logic, Algorithms and Data Structures, Date : April 26,

More information

Compiling Techniques

Compiling Techniques Lecture 11: Introduction to 13 November 2015 Table of contents 1 Introduction Overview The Backend The Big Picture 2 Code Shape Overview Introduction Overview The Backend The Big Picture Source code FrontEnd

More information

Queues. Principles of Computer Science II. Basic features of Queues

Queues. Principles of Computer Science II. Basic features of Queues Queues Principles of Computer Science II Abstract Data Types Ioannis Chatzigiannakis Sapienza University of Rome Lecture 9 Queue is also an abstract data type or a linear data structure, in which the first

More information

Binary Search Trees. Motivation

Binary Search Trees. Motivation Binary Search Trees Motivation Searching for a particular record in an unordered list takes O(n), too slow for large lists (databases) If the list is ordered, can use an array implementation and use binary

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 6:

CMSC 132, Object-Oriented Programming II Summer Lecture 6: CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 6: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 6.1 Singly

More information

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification

More information

Tutorial 4. Dynamic Set: Amortized Analysis

Tutorial 4. Dynamic Set: Amortized Analysis Tutorial 4 Dynamic Set: Amortized Analysis Review Binary tree Complete binary tree Full binary tree 2-tree P115 Unlike common binary tree, the base case is not an empty tree, but a external node Heap Binary

More information

Introduction to Computing II (ITI1121) FINAL EXAMINATION

Introduction to Computing II (ITI1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification

More information

Insert Sorted List Insert as the Last element (the First element?) Delete Chaining. 2 Slide courtesy of Dr. Sang-Eon Park

Insert Sorted List Insert as the Last element (the First element?) Delete Chaining. 2 Slide courtesy of Dr. Sang-Eon Park 1617 Preview Data Structure Review COSC COSC Data Structure Review Linked Lists Stacks Queues Linked Lists Singly Linked List Doubly Linked List Typical Functions s Hash Functions Collision Resolution

More information

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving

More information

A Simple Implementation Technique for Priority Search Queues

A Simple Implementation Technique for Priority Search Queues A Simple Implementation Technique for Priority Search Queues RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: ralf@cs.uu.nl Homepage: http://www.cs.uu.nl/~ralf/ April,

More information

Warmup. A programmer s wife tells him, Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen.

Warmup. A programmer s wife tells him, Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen. Warmup A programmer s wife tells him, Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen. The programmer returns with 12 loaves of bread. Section 3:

More information

Part I: Definitions and Properties

Part I: Definitions and Properties Turing Machines Part I: Definitions and Properties Finite State Automata Deterministic Automata (DFSA) M = {Q, Σ, δ, q 0, F} -- Σ = Symbols -- Q = States -- q 0 = Initial State -- F = Accepting States

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Intoduction to Computing II Macel Tucotte School of Electical Engineeing and Compute Science Abstact data type: Stack Stack-based algoithms Vesion of Febuay 2, 2013 Abstact These lectue notes

More information

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ; 1 Trees The next major set of data structures belongs to what s called Trees. They are called that, because if you try to visualize the structure, it kind of looks like a tree (root, branches, and leafs).

More information

Theory of Computation

Theory of Computation Theory of Computation Lecture #10 Sarmad Abbasi Virtual University Sarmad Abbasi (Virtual University) Theory of Computation 1 / 43 Lecture 10: Overview Linear Bounded Automata Acceptance Problem for LBAs

More information

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Introduction

More information

Notes for Comp 497 (Comp 454) Week 10 4/5/05

Notes for Comp 497 (Comp 454) Week 10 4/5/05 Notes for Comp 497 (Comp 454) Week 10 4/5/05 Today look at the last two chapters in Part II. Cohen presents some results concerning context-free languages (CFL) and regular languages (RL) also some decidability

More information

Algorithms. Jordi Planes. Escola Politècnica Superior Universitat de Lleida

Algorithms. Jordi Planes. Escola Politècnica Superior Universitat de Lleida Algorithms Jordi Planes Escola Politècnica Superior Universitat de Lleida 2016 Syllabus What s been done Formal specification Computational Cost Transformation recursion iteration Divide and conquer Sorting

More information

CSC D70: Compiler Optimization Static Single Assignment (SSA)

CSC D70: Compiler Optimization Static Single Assignment (SSA) CSC D70: Compiler Optimization Static Single Assignment (SSA) Prof. Gennady Pekhimenko University of Toronto Winter 08 The content of this lecture is adapted from the lectures of Todd Mowry and Phillip

More information

Topics on Compilers

Topics on Compilers Assignment 2 4541.775 Topics on Compilers Sample Solution 1. Test for dependences on S. Write down the subscripts. Which positions are separable, which are coupled? Which dependence test would you apply

More information

Searching, mainly via Hash tables

Searching, mainly via Hash tables Data structures and algorithms Part 11 Searching, mainly via Hash tables Petr Felkel 26.1.2007 Topics Searching Hashing Hash function Resolving collisions Hashing with chaining Open addressing Linear Probing

More information

Amortized analysis. Amortized analysis

Amortized analysis. Amortized analysis In amortized analysis the goal is to bound the worst case time of a sequence of operations on a data-structure. If n operations take T (n) time (worst case), the amortized cost of an operation is T (n)/n.

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26. Homework #2. ( Due: Nov 8 )

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26. Homework #2. ( Due: Nov 8 ) CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26 Homework #2 ( Due: Nov 8 ) Task 1. [ 80 Points ] Average Case Analysis of Median-of-3 Quicksort Consider the median-of-3 quicksort algorithm

More information

10:00 12:30. Do not open this problem booklet until the start of the examination is announced.

10:00 12:30. Do not open this problem booklet until the start of the examination is announced. 21 I 20 8 26 10:00 12:30 (1),. Do not open this problem booklet until the start of the examination is announced. (2) 4.. Answer the following 4 problems. Use the designated answer sheet for each problem.

More information

Assignment 4. CSci 3110: Introduction to Algorithms. Sample Solutions

Assignment 4. CSci 3110: Introduction to Algorithms. Sample Solutions Assignment 4 CSci 3110: Introduction to Algorithms Sample Solutions Question 1 Denote the points by p 1, p 2,..., p n, ordered by increasing x-coordinates. We start with a few observations about the structure

More information

Computer Science Introductory Course MSc - Introduction to Java

Computer Science Introductory Course MSc - Introduction to Java Computer Science Introductory Course MSc - Introduction to Java Lecture 3:,, Pablo Oliveira ENST Outline 1 2 3 Definition An exception is an event that indicates an abnormal condition

More information

AMORTIZED ANALYSIS. binary counter multipop stack dynamic table. Lecture slides by Kevin Wayne. Last updated on 1/24/17 11:31 AM

AMORTIZED ANALYSIS. binary counter multipop stack dynamic table. Lecture slides by Kevin Wayne. Last updated on 1/24/17 11:31 AM AMORTIZED ANALYSIS binary counter multipop stack dynamic table Lecture slides by Kevin Wayne http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated on 1/24/17 11:31 AM Amortized analysis Worst-case

More information

PSTricks. pst-ode. A PSTricks package for solving initial value problems for sets of Ordinary Differential Equations(ODE), v0.12.

PSTricks. pst-ode. A PSTricks package for solving initial value problems for sets of Ordinary Differential Equations(ODE), v0.12. PSTricks pst-ode A PSTricks package for solving initial value problems for sets of Ordinary Differential Equations(ODE), v0.12 https://gitlab.com/agrahn/pst-ode 7th June 2018 Package author(s): Alexander

More information

ENS Lyon Camp. Day 5. Basic group. C October

ENS Lyon Camp. Day 5. Basic group. C October ENS Lyon Camp. Day 5. Basic group. C++. 30 October Contents 1 Input/Output 1 1.1 C-style.......................................... 1 1. C++-style........................................ Stack Overflow

More information

Since CFL is closed under intersection with regular languages, we can do

Since CFL is closed under intersection with regular languages, we can do Exercise 7.3.1 Show that the operation cycle preserves context-free languages, where cycle is defined by: cycle(l) = {xy yx L} Informally, cycle(l) allows all strings constructed as follows: take a string

More information

Data Structures and Algorithm. Xiaoqing Zheng

Data Structures and Algorithm. Xiaoqing Zheng Data Structures and Algorithm Xiaoqing Zheng zhengxq@fudan.edu.cn MULTIPOP top[s] = 6 top[s] = 2 3 2 8 5 6 5 S MULTIPOP(S, x). while not STACK-EMPTY(S) and k 0 2. do POP(S) 3. k k MULTIPOP(S, 4) Analysis

More information

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata. Pushdown Automata We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata. Next we consider a more powerful computation model, called a

More information

Notes for Comp 497 (454) Week 10

Notes for Comp 497 (454) Week 10 Notes for Comp 497 (454) Week 10 Today we look at the last two chapters in Part II. Cohen presents some results concerning the two categories of language we have seen so far: Regular languages (RL). Context-free

More information

MTH401A Theory of Computation. Lecture 17

MTH401A Theory of Computation. Lecture 17 MTH401A Theory of Computation Lecture 17 Chomsky Normal Form for CFG s Chomsky Normal Form for CFG s For every context free language, L, the language L {ε} has a grammar in which every production looks

More information

Lecture 14: Nov. 11 & 13

Lecture 14: Nov. 11 & 13 CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 14: Nov. 11 & 13 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 14.1 Sorting

More information

CS-141 Exam 2 Review October 19, 2016 Presented by the RIT Computer Science Community

CS-141 Exam 2 Review October 19, 2016 Presented by the RIT Computer Science Community CS-141 Exam 2 Review October 19, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu Linked Lists 1. You are given the linked list: 1 2 3. You may assume that each node has one field

More information

Abstract Data Types. EECS 214, Fall 2017

Abstract Data Types. EECS 214, Fall 2017 Abstract Data Types EECS 214, Fall 2017 2 What is an ADT? An ADT defines: A set of (abstract) values A set of (abstract) operations on those values 2 What is an ADT? An ADT defines: A set of (abstract)

More information

CS481F01 Prelim 2 Solutions

CS481F01 Prelim 2 Solutions CS481F01 Prelim 2 Solutions A. Demers 7 Nov 2001 1 (30 pts = 4 pts each part + 2 free points). For this question we use the following notation: x y means x is a prefix of y m k n means m n k For each of

More information

The Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010

The Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010 The Midterm Exam Hsuan-Tien Lin Department of CSIE, NTU OOP Class, April 26-27, 2010 H.-T. Lin (NTU CSIE) The Midterm Exam OOP 04/26-27/2010 0 / 20 Java Night Countdown I 1 (2%) What is the fully-qualified

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION CSE 105 THEORY OF COMPUTATION Spring 2016 http://cseweb.ucsd.edu/classes/sp16/cse105-ab/ Today's learning goals Sipser Ch 3.3, 4.1 State and use the Church-Turing thesis. Give examples of decidable problems.

More information

Computability and Complexity

Computability and Complexity Computability and Complexity Push-Down Automata CAS 705 Ryszard Janicki Department of Computing and Software McMaster University Hamilton, Ontario, Canada janicki@mcmaster.ca Ryszard Janicki Computability

More information

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 10 - November 14 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Adding Finding and Removing

More information

Please give details of your answer. A direct answer without explanation is not counted.

Please give details of your answer. A direct answer without explanation is not counted. Please give details of your answer. A direct answer without explanation is not counted. Your answers must be in English. Please carefully read problem statements. During the exam you are not allowed to

More information

Binary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016

Binary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016 Binary Search Trees Lecture 29 Section 19.2 Robb T. Koether Hampden-Sydney College Fri, Apr 8, 2016 Robb T. Koether (Hampden-Sydney College) Binary Search Trees Fri, Apr 8, 2016 1 / 40 1 Binary Search

More information

Appendix of Computational Protein Design Using AND/OR Branch and Bound Search

Appendix of Computational Protein Design Using AND/OR Branch and Bound Search Appendix of Computational Protein Design Using AND/OR Branch and Bound Search Yichao Zhou 1, Yuexin Wu 1, and Jianyang Zeng 1,2, 1 Institute for Interdisciplinary Information Sciences, Tsinghua University,

More information

Heaps and Priority Queues

Heaps and Priority Queues Heaps and Priority Queues Motivation Situations where one has to choose the next most important from a collection. Examples: patients in an emergency room, scheduling programs in a multi-tasking OS. Need

More information

Bin Sort. Sorting integers in Range [1,...,n] Add all elements to table and then

Bin Sort. Sorting integers in Range [1,...,n] Add all elements to table and then Sorting1 Bin Sort Sorting integers in Range [1,...,n] Add all elements to table and then Retrieve in order 1,2,3,...,n Stable Sorting Method (repeated elements will end up in their original order) Numbers

More information

Construction of Static Single-Assignment Form

Construction of Static Single-Assignment Form COMP 506 Rice University Spring 2018 Construction of Static Single-Assignment Form Part II source IR IR target code Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all

More information

Rumination on the Formal Definition of DPDA

Rumination on the Formal Definition of DPDA Rumination on the Formal Definition of DPDA In the definition of DPDA, there are some parts that do not agree with our intuition. Let M = (Q, Σ, Γ, δ, q 0, Z 0, F ) be a DPDA. According to the definition,

More information

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where Recitation 11 Notes Context Free Grammars Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x A V, and x (V T)*. Examples Problem 1. Given the

More information

FP-growth and PrefixSpan

FP-growth and PrefixSpan FP-growth and PrefixSpan n Challenges of Frequent Pattern Mining n Improving Apriori n Fp-growth n Fp-tree n Mining frequent patterns with FP-tree n PrefixSpan Challenges of Frequent Pattern Mining n Challenges

More information

Speculative Parallelism in Cilk++

Speculative Parallelism in Cilk++ Speculative Parallelism in Cilk++ Ruben Perez & Gregory Malecha MIT May 11, 2010 Ruben Perez & Gregory Malecha (MIT) Speculative Parallelism in Cilk++ May 11, 2010 1 / 33 Parallelizing Embarrassingly Parallel

More information

Lecture Overview SSA Maximal SSA Semipruned SSA o Placing -functions o Renaming Translation out of SSA Using SSA: Sparse Simple Constant Propagation

Lecture Overview SSA Maximal SSA Semipruned SSA o Placing -functions o Renaming Translation out of SSA Using SSA: Sparse Simple Constant Propagation 1 Lecture Overview SSA Maximal SSA Semipruned SSA o Placing -functions o Renaming Translation out of SSA Using SSA: Sparse Simple Constant Propagation [Chapter 9] 2 SSA Revisited It is desirable to use

More information

Section 1 (closed-book) Total points 30

Section 1 (closed-book) Total points 30 CS 454 Theory of Computation Fall 2011 Section 1 (closed-book) Total points 30 1. Which of the following are true? (a) a PDA can always be converted to an equivalent PDA that at each step pops or pushes

More information

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10 Merge Sort 1 / 10 Outline 1 Merging 2 Merge Sort 3 Complexity of Sorting 4 Merge Sort and Other Sorts 2 / 10 Merging Merge sort is based on a simple operation known as merging: combining two ordered arrays

More information

Lecture 7: Amortized analysis

Lecture 7: Amortized analysis Lecture 7: Amortized analysis In many applications we want to minimize the time for a sequence of operations. To sum worst-case times for single operations can be overly pessimistic, since it ignores correlation

More information

Solutions to EoPL3 Exercises

Solutions to EoPL3 Exercises Solutions to EoPL3 Exercises Release 0.1.0 Cheng Lian May 16, 2017 Contents 1 Contents 3 2 Overview 29 i ii Author Cheng Lian Contents 1 2 Contents CHAPTER 1 Contents Chapter 1.

More information

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 7 - November 11 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Accessing and Modifying

More information

Programming with classical quantum datatypes

Programming with classical quantum datatypes Programming with classical quantum datatypes Robin Cockett & Brett Giles (robin,gilesb)@cpsc.ucalgary.ca University of Calgary FMCS 2006, Programming with classical quantum datatypes p. 1/49 Yet another

More information

Übung Informatik I - Programmierung - Blatt 7

Übung Informatik I - Programmierung - Blatt 7 RHEINISCH- WESTFÄLISCHE TECHNISCHE HOCHSCHULE AACHEN LEHR- UND FORSCHUNGSGEBIET INFORMATIK II RWTH Aachen D-52056 Aachen GERMANY http://programmierung.informatik.rwth-aachen.de LuFG Informatik II Prof.

More information

MATHEMATICAL OBJECTS in

MATHEMATICAL OBJECTS in MATHEMATICAL OBJECTS in Computational Tools in a Unified Object-Oriented Approach Yair Shapira @ CRC Press Taylor & Francis Group Boca Raton London New York CRC Press is an imprint of the Taylor & Francis

More information

CS361 Homework #3 Solutions

CS361 Homework #3 Solutions CS6 Homework # Solutions. Suppose I have a hash table with 5 locations. I would like to know how many items I can store in it before it becomes fairly likely that I have a collision, i.e., that two items

More information

CISC4090: Theory of Computation

CISC4090: Theory of Computation CISC4090: Theory of Computation Chapter 2 Context-Free Languages Courtesy of Prof. Arthur G. Werschulz Fordham University Department of Computer and Information Sciences Spring, 2014 Overview In Chapter

More information

CS 21 Decidability and Tractability Winter Solution Set 3

CS 21 Decidability and Tractability Winter Solution Set 3 CS 21 Decidability and Tractability Winter 2018 Posted: January 31 Solution Set 3 If you have not yet turned in the Problem Set, you should not consult these solutions. 1. (a) A 2-NPDA is a 7-tuple (Q,,

More information

Skip Lists. What is a Skip List. Skip Lists 3/19/14

Skip Lists. What is a Skip List. Skip Lists 3/19/14 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 Skip Lists 15 15 23 10 15 23 36 Skip Lists

More information

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Language Processing Systems Prof. Mohamed Hamada Software Engineering La. The University of izu Japan Syntax nalysis (Parsing) 1. Uses Regular Expressions to define tokens 2. Uses Finite utomata to recognize

More information

Tute 10. Liam O'Connor. May 23, 2017

Tute 10. Liam O'Connor. May 23, 2017 Tute 10 Liam O'Connor May 23, 2017 proc Search(value g : G, value s : V g, value k : K, result v : T, result f : B) Where a graph g : G is dened as a 4-tuple (V, Γ, κ, λ) containing a set of vertices V,

More information

Syntax Analysis Part III

Syntax Analysis Part III Syntax Analysis Part III Chapter 4: Top-Down Parsing Slides adapted from : Robert van Engelen, Florida State University Eliminating Ambiguity stmt if expr then stmt if expr then stmt else stmt other The

More information

Representing Multidimensional Trees. David Brown, Colin Kern, Alex Lemann, Greg Sandstrom Earlham College

Representing Multidimensional Trees. David Brown, Colin Kern, Alex Lemann, Greg Sandstrom Earlham College Representing Multidimensional Trees David rown, Colin Kern, lex Lemann, Greg andstrom Earlham College 1 Introduction Presentation Layout Dave: n Introduction to Multidimensional Trees and Grammars lex:

More information

Context-Free Languages

Context-Free Languages CS:4330 Theory of Computation Spring 2018 Context-Free Languages Pushdown Automata Haniel Barbosa Readings for this lecture Chapter 2 of [Sipser 1996], 3rd edition. Section 2.2. Finite automaton 1 / 13

More information

MiniMat: Matrix Language in OCaml LLVM

MiniMat: Matrix Language in OCaml LLVM Terence Lim - tl2735@columbia.edu August 17, 2016 Contents 1 Introduction 4 1.1 Goals........................................ 4 1.1.1 Flexible matrix notation......................... 4 1.1.2 Uncluttered................................

More information

HW #4. (mostly by) Salim Sarımurat. 1) Insert 6 2) Insert 8 3) Insert 30. 4) Insert S a.

HW #4. (mostly by) Salim Sarımurat. 1) Insert 6 2) Insert 8 3) Insert 30. 4) Insert S a. HW #4 (mostly by) Salim Sarımurat 04.12.2009 S. 1. 1. a. 1) Insert 6 2) Insert 8 3) Insert 30 4) Insert 40 2 5) Insert 50 6) Insert 61 7) Insert 70 1. b. 1) Insert 12 2) Insert 29 3) Insert 30 4) Insert

More information

Lecture 4: Nondeterministic Finite Automata

Lecture 4: Nondeterministic Finite Automata Lecture 4: Nondeterministic Finite Automata Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (26/09/17) Lecture 4: Nondeterministic Finite Automata 2017-2018 1 /

More information

Data Structures and Algorithms " Search Trees!!

Data Structures and Algorithms  Search Trees!! Data Structures and Algorithms " Search Trees!! Outline" Binary Search Trees! AVL Trees! (2,4) Trees! 2 Binary Search Trees! "! < 6 2 > 1 4 = 8 9 Ordered Dictionaries" Keys are assumed to come from a total

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION CSE 105 THEORY OF COMPUTATION Spring 2017 http://cseweb.ucsd.edu/classes/sp17/cse105-ab/ Review of CFG, CFL, ambiguity What is the language generated by the CFG below: G 1 = ({S,T 1,T 2 }, {0,1,2}, { S

More information

CS 5321: Advanced Algorithms Amortized Analysis of Data Structures. Motivations. Motivation cont d

CS 5321: Advanced Algorithms Amortized Analysis of Data Structures. Motivations. Motivation cont d CS 5321: Advanced Algorithms Amortized Analysis of Data Structures Ali Ebnenasir Department of Computer Science Michigan Technological University Motivations Why amortized analysis and when? Suppose you

More information

Efficient Enumeration of Regular Languages

Efficient Enumeration of Regular Languages Efficient Enumeration of Regular Languages Margareta Ackerman and Jeffrey Shallit University of Waterloo, Waterloo ON, Canada mackerma@uwaterloo.ca, shallit@graceland.uwaterloo.ca Abstract. The cross-section

More information

Premaster Course Algorithms 1 Chapter 3: Elementary Data Structures

Premaster Course Algorithms 1 Chapter 3: Elementary Data Structures Premaster Course Algorithms 1 Chapter 3: Elementary Data Structures Christian Scheideler SS 2018 23.04.2018 Chapter 3 1 Overview Basic data structures Search structures (successor searching) Dictionaries

More information

On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work

On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work Lab 5 : Linking Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The main objective of this lab is to experiment

More information

Models of Computation. by Costas Busch, LSU

Models of Computation. by Costas Busch, LSU Models of Computation by Costas Busch, LSU 1 Computation CPU memory 2 temporary memory input memory CPU output memory Program memory 3 Example: f ( x) x 3 temporary memory input memory Program memory compute

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 7: LL(1) Parsing Zheng (Eddy) Zhang Rutgers University February 7, 2018 Class Information Homework 3 will be posted this coming Monday. 2 Review: Top-Down

More information

Outline 1 PCP. 2 Decision problems about CFGs. M.Mitra (ISI) Post s Correspondence Problem 1 / 10

Outline 1 PCP. 2 Decision problems about CFGs. M.Mitra (ISI) Post s Correspondence Problem 1 / 10 Outline 1 PCP 2 Decision problems about CFGs M.Mitra (ISI) Post s Correspondence Problem 1 / 10 PCP reduction Given: M, w in encoded form To construct: an instance (A, B) of MPCP such that M accepts w

More information

Pushdown Automata. Chapter 12

Pushdown Automata. Chapter 12 Pushdown Automata Chapter 12 Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely what it needs is a stack, which gives it an unlimited

More information

Skip List. CS 561, Lecture 11. Skip List. Skip List

Skip List. CS 561, Lecture 11. Skip List. Skip List Skip List CS 561, Lecture 11 Jared Saia University of New Mexico Technically, not a BST, but they implement all of the same operations Very elegant randomized data structure, simple to code but analysis

More information

(pp ) PDAs and CFGs (Sec. 2.2)

(pp ) PDAs and CFGs (Sec. 2.2) (pp. 117-124) PDAs and CFGs (Sec. 2.2) A language is context free iff all strings in L can be generated by some context free grammar Theorem 2.20: L is Context Free iff a PDA accepts it I.e. if L is context

More information

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever.   ETH Zürich (D-ITET) October, Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu ETH Zürich (D-ITET) October, 19 2017 Part 5 out of 5 Last week was all about Context-Free Languages Context-Free

More information

CS20a: Turing Machines (Oct 29, 2002)

CS20a: Turing Machines (Oct 29, 2002) CS20a: Turing Machines (Oct 29, 2002) So far: DFA = regular languages PDA = context-free languages Today: Computability 1 Church s thesis The computable functions are the same as the partial recursive

More information

Constructors - Cont. must be distinguished by the number or type of their arguments.

Constructors - Cont. must be distinguished by the number or type of their arguments. Constructors - Cont. 1 Constructors can be overloaded! must be distinguished by the number or type of their arguments. 2 When no constructor is defined, there is a default constructor with no arguments.

More information

Non-context-Free Languages. CS215, Lecture 5 c

Non-context-Free Languages. CS215, Lecture 5 c Non-context-Free Languages CS215, Lecture 5 c 2007 1 The Pumping Lemma Theorem. (Pumping Lemma) Let be context-free. There exists a positive integer divided into five pieces, Proof for for each, and..

More information

CSE302: Compiler Design

CSE302: Compiler Design CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University February 27, 2007 Outline Recap

More information

Handout 8: Computation & Hierarchical parsing II. Compute initial state set S 0 Compute initial state set S 0

Handout 8: Computation & Hierarchical parsing II. Compute initial state set S 0 Compute initial state set S 0 Massachusetts Institute of Technology 6.863J/9.611J, Natural Language Processing, Spring, 2001 Department of Electrical Engineering and Computer Science Department of Brain and Cognitive Sciences Handout

More information