CS W3134: Data Structures in Java

Similar documents
CS 206 Introduction to Computer Science II

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

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

Postfix (and prefix) notation

CS 206 Introduction to Computer Science II

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

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

DEEPIKA KAMBOJ UNIT 2. What is Stack?

March 13/2003 Jayakanth Srinivasan,

The Stack and Queue Types

PA3 Design Specification

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

Stacks, Queues and Hierarchical Collections

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

Lecture Data Structure Stack

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

An Introduction to Trees

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

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

Introduction. Reference

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

Lab 7 1 Due Thu., 6 Apr. 2017

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

STACKS AND QUEUES. Problem Solving with Computers-II

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

12 Abstract Data Types

DATA STRUCTURES AND ALGORITHMS

TREES. Trees - Introduction

1/30/2018. Conventions Provide Implicit Information. ECE 220: Computer Systems & Programming. Arithmetic with Trees is Unambiguous

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

Stacks, Queues (cont d)

CSE 214 Computer Science II Stack

Arrays and Linked Lists

Recursive Data Structures and Grammars

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

Linear Data Structure

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

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

Programming Abstractions

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

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

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

Lecture 4 Stack and Queue

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Stack Abstract Data Type

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

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

Assessment of Programming Skills of First Year CS Students: Problem Set

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack.

Programming Abstractions

COMP 250 Fall binary trees Oct. 27, 2017

Content: Learning Objectives

ADTS, GRAMMARS, PARSING, TREE TRAVERSALS

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

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

Data Structures and Algorithms

// The next 4 functions return true on success, false on failure

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

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

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

1. Stack Implementation Using 1D Array

Computer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

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

Stating the obvious, people and computers do not speak the same language.

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1

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

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

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Lauren Milne Summer 2015

Data Structures. 1. Each entry in a linked list is a called a (a)link (b)node (c)data structure (d)none of the above

Stacks Fall 2018 Margaret Reid-Miller

List, Stack, and Queues

Algorithms and Data Structures

3137 Data Structures and Algorithms in C++

DATA STRUCTURE UNIT I

Prefix/Infix/Postfix Notation

Programming Abstractions

CS200: Queues. Prichard Ch. 8. CS200 - Queues 1

INSTITUTE OF AERONAUTICAL ENGINEERING

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

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

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

ADTS, GRAMMARS, PARSING, TREE TRAVERSALS. Regrades 10/6/15. Prelim 1. Prelim 1. Expression trees. Pointers to material

ADTS, GRAMMARS, PARSING, TREE TRAVERSALS

How to Win Coding Competitions: Secrets of Champions. Week 2: Computational complexity. Linear data structures Lecture 5: Stack. Queue.

Data Structures Question Bank Multiple Choice

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

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Finish Lec12 TREES, PART 2. Announcements. JavaHyperText topics. Trees, re-implemented. Iterate through data structure 3/7/19

CS61C : Machine Structures

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

CS Introduction to Data Structures How to Parse Arithmetic Expressions

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

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

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

MCA SEM-II Data Structure

CSE 230 Intermediate Programming in C and C++

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Types of Data Structures

CS 106B Lecture 5: Stacks and Queues

Transcription:

CS W3134: Data Structures in Java Lecture #10: Stacks, queues, linked lists 10/7/04 Janak J Parekh HW#2 questions? Administrivia Finish queues Stack/queue example Agenda 1

Circular queue: miscellany Having to keep count is a little extra work Book has sample code to deal with no-count implementation, but more complex Basic problem: how to tell queue empty vs. full Trick: if full, leave an empty space We re not going to do this Other queues Deque: double-ended queue essentially a stack and queue combined: insert/remove left/right Priority queue Object of highest priority will be next to be dequeued After insert, front points to highest-priority element Book s s implementation does insertion sort: starts at end, and moves elements up until it s s in the right position No benefit to using circular constructs, so very similar to naïve queue approach Complexity? (Heaps are better, but later) More complex stack example How do computers parse arithmetic expressions? First step: transform expression into postfix notation Second step: evaluate postfix expression using a stack 2

Postfix Also called Reverse Polish Notation (RPN); HP calculators Why? Parentheses unneeded no ambiguity Can process in one pass from left-to to-right Fairly straightforward to translate from infix to postfix, but let s s hold off on this Evaluating a Postfix expression Go left-to to-right If operand, push on stack If operator, pop two operands, use operator, and push result on stack When done, there should be one value on the stack Pop it Converting Infix to Postfix See pages 158-159, 159, although I think these bullets make more sense ;) Need to encode operator precedence To process: Operand: write straight to output (: push on stack ): pop all items until ( encountered, and output them; don t write the ( Input complete: pop all items and write out Operator: interesting problem 3

Converting Infix-to to-postfix (II) Operator handling If stack is empty, push Else, pop, determine precedence of new vs. popped If popped is a (, put it back on the stack, and put the new operator on top Else if new has higher precedence, push popped back on, and push new on top of it Else if popped has higher or equal precedence, output it, and repeat this process (PE)MDAS for precedence Linked lists Arrays are rather limited, cumbersome data structures cells are fixed together, limited length What if we could break apart the cells? We can! In fact, linked list-style style structures are used more frequently unless you need very fast random index- based access Trees, graphs, etc. are generalizations of linked lists Linked List structure Two basic objects: The list parent itself An element (book calls link ), with data Technically, we don t t need both Parent contains reference to the first element Each element contains a reference to the next element Last element s next is set to null 4

Basic Linked List operations How to tell if empty? Insertions insertfirst() deletefirst() displaylist() insertlast() More complex operations How to find an arbitrary element? How to delete arbitrary element? Double-ended ended list Contains pointer to last element Makes insertlast() much faster (how much?) Linked list complexity? Similar to arrays O(1) insert/delete at beginning (or end of list for double-ended) ended) Other operations take O(N), but faster than array if sliding is needed in array Memory? Linked list more efficient, although it has to keep lots of references 5

Revisit abstraction Book finally covers abstraction here We can redo all of our previous data structures, previously array-backed backed,, as linked list-backed Interface high-level contract, while the dirty details are hidden How to do a stack? How to do a queue? You should read through this section Finish Linked Lists Start Recursion Next time 6