March 13/2003 Jayakanth Srinivasan,

Similar documents
Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

STACKS AND QUEUES. Problem Solving with Computers-II

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

Merge Sort. Run time typically depends on: Insertion sort can be faster than merge sort. Fast, able to handle any data

Lecture 12 ADTs and Stacks

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

Formal Languages and Automata Theory, SS Project (due Week 14)

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

Stacks. Revised based on textbook author s notes.

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

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

Stacks. Manolis Koubarakis. Data Structures and Programming Techniques

Outline. Stacks. 1 Chapter 5: Stacks and Queues. favicon. CSI33 Data Structures

CS 206 Introduction to Computer Science II

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Stack Abstract Data Type

The Stack and Queue Types

CSE 214 Computer Science II Stack

Lecture 4: Stack Applications CS2504/CS4092 Algorithms and Linear Data Structures. Parentheses and Mathematical Expressions

CSCI 204 Introduction to Computer Science II. Lab 6: Stack ADT

CS W3134: Data Structures in Java

12 Abstract Data Types

An Introduction to Trees

Stacks Calculator Application. Alexandra Stefan

Stack and Its Implementation

Lecture Data Structure Stack

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Stacks and their Applications

DATA STRUCTURES AND ALGORITHMS

CISC-235. At this point we fnally turned our atention to a data structure: the stack

PA3 Design Specification

Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5

CS 211 Programming Practicum Spring 2018

Stacks Fall 2018 Margaret Reid-Miller

CS 171: Introduction to Computer Science II. Stacks. Li Xiong

Stacks, Queues (cont d)

Linear Data Structure

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

CS 211 Programming Practicum Spring 2017

Introduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms

Postfix (and prefix) notation

Lecture 4 Stack and Queue

Lecture 8: Simple Calculator Application

CMPT 225. Stacks-part2

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

ABSTRACT DATA TYPES (ADTS) COMP1927 Computing 2 16x1 Sedgewick Chapter 4

Programming, Data Structures and Algorithms Prof. Hema A Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Stacks. CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack.

Stacks, Queues and Hierarchical Collections

Project 1: Implementation of the Stack ADT and Its Application

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

SimpleCalc. which can be entered into a TI calculator, like the one on the right, like this:

CSE 230 Intermediate Programming in C and C++

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues

CS 211 Programming Practicum Fall 2018

CS 206 Introduction to Computer Science II

Data Structures Week #3. Stacks

Top of the Stack. Stack ADT

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.

Containers: Stack. Jordi Cortadella and Jordi Petit Department of Computer Science

Lab 7 1 Due Thu., 6 Apr. 2017

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

CS 211. Project 5 Infix Expression Evaluation

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

Containers: Stack. The Stack ADT. The Stack ADT. The Stack ADT

Outline. Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications. ADT for stacks

DEEPIKA KAMBOJ UNIT 2. What is Stack?

CSCI 200 Lab 4 Evaluating infix arithmetic expressions

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Lecture Chapter 6 Recursion as a Problem Solving Technique

[CS302-Data Structures] Homework 2: Stacks

This is an individual assignment and carries 100% of the final CPS 1000 grade.

IV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard

BBM 201 DATA STRUCTURES

infix expressions (review)

BBM 201 DATA STRUCTURES

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

Data Structures and Algorithms

Data Structures and Algorithms

ADT Stack. Inserting and deleting elements occurs at the top of Stack S. top. bottom. Stack S

Types of Data Structures

A Simple Syntax-Directed Translator

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

n Data structures that reflect a temporal relationship q order of removal based on order of insertion n We will consider:

Top of the Stack. Stack ADT

Recursive Data Structures and Grammars

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

08 STACKS DATA STRUCTURES AND ALGORITHMS IMPLEMENTATION & APPLICATIONS IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD

Foundations of Data Structures

CISC

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

Monday, November 13, 2017

Solution: The examples of stack application are reverse a string, post fix evaluation, infix to postfix conversion.

Stacks CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008

Stacks II. Adventures in Notation. stacks2 1

Review: Expressions, Variables, Loops, and more.

Transcription:

Statement Effort MergeSort(A, lower_bound, upper_bound) begin T(n) if (lower_bound < upper_bound) Θ(1) mid = (lower_bound + upper_bound)/ 2 Θ(1) MergeSort(A, lower_bound, mid) T(n/2) MergeSort(A, mid+1, upper_bound) T(n/2) Merge(A, lower_bound, mid,upper_bound) Θ(n) end So T(n) = Θ(1) when n = 1, and 2T(n/2) + Θ(n) when n > 1 So what (more succinctly) is T(n)?

ADT: A collection of data and functions that operate on the data. since it is abstract, we do not need to specify languagespecific data types or functions. specify the collection by the general way in which the data is stored, and describe the actions of the functions. Linear List : An ordered collection of data; that is, the data is arranged into some order (not necessarily sorted), so that data is referenced by its position within the list

2 Subclasses Stacks Queues Operation Initialize Empty Insert Delete Explanation Initialize the internal structure of the list, make sure it s empty Returns true iff the list is empty Inserts a new element after the k th element; if k is zero, then insert at the beginning of the list Delete the k th item in the list.

Subclass of Linear Lists Access restricted to one end of the list called the Top Operation Description Initialize Push Pop Empty StackTop Size Initialize internal structure; create empty stack Add new element to top of stack Remove top element from stack True iff stack has no elements Returns copy of top element of stack (without popping it) Returns number of elements in the stack

Reversing data Parsing Postponement Backtracking

Parsing is the process of breaking down a string into constituent components and determining the structure of the component sequence Checking if expressions are balanced Process the string from left to right, one character at a time When a left parenthesis is found, push it onto the stack When a right parenthesis is found, if the stack is empty then there is a mismatch (R without L), otherwise pop the stack once (to remove the matching left parenthesis) When done, if the stack is empty, then the parentheses are balanced, otherwise there is a mismatch (L without R).

Sometimes data within a list is not processed when it is encountered; rather, processing must be deferred until a later step. postfix evaluation is a classic example of postponement. In postfix notation, operators appear after their operand, so that 1 + 2 in our normal (infix) notation becomes 1 2 +.

Infix Postfix a * b a b * a + b * c a b c * + a * b + c a b * c + (a + b) * c + d + e * f - g a b + c * d + e f * + g -

1. Initialize stack 2. For each item x in the expression, from left to right, do 2.1-2.2. 2.1. If x is a number (or variable), Then 2.1.1. Push x onto stack 2.2. Else (x is an operator (+, -, *, /)) 2.2.1. Pop op 2 from stack 2.2.2. Pop op 1 from stack (notice the reverse order) 2.2.3. Perform the operation: op 1 x op 2 2.2.4. Push the result onto the stack 3. Pop answer from the stack

1. Set postfix string to empty string 2. Create an empty operator stack 3. Repeat 3.1 Get the next token in the infix string 3.2 If next token is an operand (begins with digit), append it to postfix string 3.3 If next token is an operator 3.3.1 Process the next operator

Set done to false Repeat If operator stack is empty or next op is (, push next op onto stack and set done to true Else if precedence(next op) > precedence(top operator) Push next op onto the stack (ensures higher precedence operators evaluated first) and set done to true Else Pop the operator stack If operator popped is (, set done to true Else append operator popped to postfix string Until done

Infix Expression 3 + 5 * 6 7 * (8 + 5) Postfix Expression 3 5 6 * + 7 8 5 + *