COSC This week. List ADT. Abstract Data Type (ADT) Lis t ADT Implementations. Data Struc tures and Algorithms
|
|
- Wesley Harmon
- 5 years ago
- Views:
Transcription
1 This week COSC Week 9, March 8, 2004 Read chapter 19 Work on assignment #3 Discussed in Tutorial this week Must have a partial solution shown to your TA next week. Data structures (continued) S tacks, Queues, Lists, S ets, Lecture7 notes are used for both weeks 7 and 8 (no additional notes for week 8). Abstract Data Type (ADT) Abstract Data Type (ADT): a mode l of a set of data together with operations allowed on them. Hence it defines a type. abstract implies the model specifies what needs to be done rather than how it should be done (devoid of any implementation details) J ava allows you to define your own types List ADT Allows the following operations add(object): add to the end of the list remove(index): remove the one at index size(): get the size of the list get(index): get the object at index etc. However, it does not specify how these operations are carried out Lis t ADT Implementations Data Struc tures and Algorithms List ADT with two implementations Array head φ A data structure provides means of organizing data examples: array, linked list, tree (hierarchical) An algorithm provides a clear, step by step, instructions for solving a problem. The terms data structure and ADT have been used interchangeably Linked structure 1
2 Historical Notes S tructured programming (1970s): emphasis on the use of procedures emphasis on top-down design reflected in Pascal, C, Modular-2 Object-oriented programming(1980s): emphasis on abstract data types ability to change implementation of an ADT emphasis on bottom-up design reflected in J ava, C++, Eiffel, S malltalk Other ADTs ADT S tack: linear structure (LIFO) Queue: linear structure (FIFO) Tree: hierarchical Stack ADT The S tack ADT stores arbitrary objects Insertions, deletions follow the last-in-first-out Think of a spring-loaded plate dispenser S tack operations: push(object): inserts an element object pop(): removes and returns the last inserted element object top(): returns the last inserted element without removing it integer size(): returns the number of elements stored boolean isempty(): indicates whether stack is empty Applications of Stack Direct applications Page-visited history in a Web browser Undo sequence in a text editor Chain of method calls in the J ava Virtual Machine Indirect applications Auxiliary data structure for algorithms Component of other data structures Stack in J VM From Data Structures and Algorithms in J ava by Goodrich and Tamassia Stac k Implementation The J ava Virtual Machine (J VM) keeps track of the chain of active methods with a stack When a method is called, the J VM pushes on the stack a frame containing Local variables and return value Program counter, keeping track of the statement being executed When a method ends, its frame is popped from the stack and control is passed to the method on top of the stack main() { int i = 5; foo(i); foo(int j) { int k; k = j+1; bar(k); bar(int m) { S implification of a linked list Add/remove at one end of the list Covered in previous lectures Implementation using an array S tart with a maximum size 2
3 public class ArrayStack { private Object[] elems; private int sp; private static final int MAXSIZE = 100; public ArrayStack() { elems = new Object[MAXSIZE]; sp = 0; public void push(object o) { if(sp >= MAXSIZE) throw new RuntimeException("ArrayStack stack overflow"); elems[sp] = o; sp++; public boolean isempty() { return sp == 0; public Object pop() { if(sp <= 0) throw new RuntimeException("ArrayStack stack underflow"); sp--; return elems[sp]; sp Array-bas ed Stac k Very efficient O(1) push, pop, isempty() Requires a predefined MaxS ize We have two options if stack becomes full: throw an exception increase the size of the array We have explored both options How to implement top using.. How to copy a stack Top operation implementation using other stack operations? peek at the top element public Object top() { Object o = pop(); push(o); return o; Copy a stack to a new stack? public ArrayStack copy() { ArrayStack st = new ArrayStack(); while(!this.isempty()) { Object o = this.pop(); st.push(o); AttaryStack st2 = new ArrayStack(); while(!st.empty()) { Object o = st.pop(); this.push(o); st2.push(o); return st2; A B C D E E D C B A A B C D E this st st2 Stack in J ava Library J ava Stack public class Stac k extends Vector The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search the stack for an item and discover how far it is from the top. When a stack is first created, it contains no items. boolean empty() Tests if this stack is empty. Object peek() Looks at the object at the top of this stack without removing it from the stack. Object pop() Removes the object at the top of this stack and returns that object as the value of this function. Object push(object item) Pushes an item onto the top of this stack. int search(object o) Returns the 1-based position where an object is on this stack. 3
4 Evaluating Pos tfix Expres s ion Algebraic expressions in infix notation: (4 + 5*(6-2)) Parenthesis are used to group subexpressions Postfix notation can be used to specify an expression without parenthesis * + Pos tfix Notation Postfix expression Infix expression A B + (A + B) ABC+* (A*(B+ C)) XYZ+- AB*/ (X - (Y + Z))/(A*B) M2^N3^-AB+* (M^2 - N^2)*(A + B) ^ represents exponentiation operator Algorithm for Evaluating a Postfix expression Create a new stack s tokens = tokenize the input string while (more tokens left){ o = next token; if o is an operand then s.push(o) else a2 = s.pop(); a1 = s.pop(); a3 = evaluate a1 o a2 s.push(a3) Evaluating Pos tfix Expres s ion public static void main(string[] args){ S tring x = "5 2 /"; S ystem.out.println(x + " = " + evalpostfix(x)); x = "5 2 ^ 3 2 ^ *"; S ystem.out.println(x + " = " + evalpostfix(x)); Output 5 2 /= ^ 3 2 ^ * = 32.0 Evaluation Pos tfix Expres s ion Output lines in reverse order static double evalpostfix(string in){ static double eval(string a1, String a2, S tring final S tring op = "+-/*^"; op) StringTokenizer tokens = new { S tringtokenizer(in); double a1val = Double.parseDouble(a1); S tack s = new S tack(); double a2val = Double.parseDouble(a2); while(tokens.hasmoretokens()){ switch(op.charat(0)){ String t = tokens.nexttoken(); case '+': return a1val + a2val; if (op.indexof(t) == -1) case '-': return a1val - a2val; s.push(t); case '*': return a1val * a2val; else { case '/': return a1val /a2val; String a2 = (String) s.pop(); case '^': return Math.pow(a1Val, String a1 = (String) s.pop(); a2val); s.push("" + eval(a1, a2, t)); return 0; return(double.parsedouble((s tring) s.pop())); Read a file, line by line, and output the lines in the order opposite to input order, using a stack File contains: to have and to hold Output: to hold and to have static void reverse(string file){ S tack s = new S tack(); UniReader ur = new UniReader(file); S tring line = ur.readline(); while (!ur.eof()){ s.push(line); line = ur.readline(); while (s.size() > 0) IO.println((S tring) s.pop()); ur.close(); 4
5 Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out Insertions are at the rear of the queue and removals are at the front of the queue queue operations: enqueue(object): inserts an element at the end of the queue object dequeue(): removes and returns the element at the front of the queue object front(): returns the element at the front without removing it integer size(): returns the number of elements stored boolean isempty(): indicates whether no elements are stored Queue Applic ations Direct applications Waiting lists, bureaucracy Access to shared resources (e.g., printer) Multiprogramming Indirect applications Auxiliary data structure for algorithms Component of other data structures Simulation Queue Implementations We have already seen this in the Hair S alon S imulation: Linked list enqueue, dequeue Events occur (people arrive) with probability p Add them to a queue front φ If able to do more work Take person from the head of the queue, and process them front φ enqueue front φ dequeue Queue Implementations J ava Queue Linked list Done previously Using an array Quite subtle Add to the end and remove from front What happens when array is filled? Idea of circular arrays back front front back Use LinkedList public class LinkedList extends AbstractSequentialList implements List, Cloneable, Serializable Linked list implementation of the List interface. Implements all optional list operations, and permits all elements (including null). In addition to implementing the List interface, the LinkedList class provides uniformly named methods to get, remove and insert an element at the beginning and end of the list. These operations allow linked lists to be used as a stack, queue, or double-ended queue (deque). 5
6 List Create, add, remove, index(), ArrayLists, LinkeLists Done in lecture earlier Great for holding a list of multiple, (different) things Like DVD s, etc. Inefficient, so not great for large N Doing things with Lists Lists are very general purpose, Large API S ize(), search functions, use of equals() Reasonably inefficient Great for small n problems though Set Create, add(), contains(), remove(), Like lists but do not contain duplicates. Add(o) fails if contains(o) is true Useful for maintaining state information Flags J ava does not support ArrayS et or LinkedS et S upport HashS et, LinkedHashS et How J ava implements Collec tions Interface java.util.collection Add(), clear(), isempty(), size(),. All classes that implement the collection must define all of these methods But can throw java.lang.unsupportedoperationexception Subclass of J ava.lang.exception java.util.abs trac tcollec tion and java.util.abs trac tsequentiallis t Abstract classes that implements the Collection interface One designed for things that have eventually implementations based on random access One designed for things based on linked lists AbstractCollection public abstract class AbstractCollection extends Object implements Collection This class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface. Direct Known Subclasses: AbstractList, AbstractS et 6
7 AbstractS equentiallist AbstractList subclasses public abstract class AbstractSequentialList extends AbstractList This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "sequential access" data store (such as a linked list). For random access data (such as an array), AbstractList should be used in preference to this class. This class is the opposite of the AbstractList class in the sense that it implements the "random access" methods (get(int index), set(int index, Object element), set(int index, Object element), add(int index, Object element) and remove(int index)) on top of the list's list iterator, instead of the other way around. ArrayList An extendable array Vector Like ArrayList but The underlying array can shrink (as well as grow) J ava.util.stack is a subclass of Vector Direct Known Subclasses: LinkedList Abs trac tsequentiallis t public interface iterator { J ava.util.linkedlist Implements the entire collection interface addfirst(), addlast(), removefirst, removelast() Internally is a doubly linked list. A queue is a trivial extension of a linkedlist public boolean hasnext(); //True iff more elements in the iterator public Object next(); //Returns next element in the iteration void remove() throws UnsupportOperationException //Removes last element obtained via next() from the collection. //Optional method - hence may throw exception How do you implement an Iterator? How to implement iterator Advanced topic Use inner classes A class can define within it, another class This class can access all of the fields of its outer class. Public MyLinkedList {.. private class MyListIterator implements Iterator{ protected MyLinkedList list; protected MyNode cur; public ListIterator(MyLinkedList ls){ list = ls; cur = list.head; public boolean hasnext(){ return (cur!= null); public Object next() throws NoSuchElementException{ if (!hasnext() ) throw new NoSuchEelementException(); Object o = cur.geto(); cur = cur.getnext(); return o; public iterator elements() { return new MyListIterator(this); 7
8 Lis ts aren t everything Major classes of data structures remain. Graph Trees Hash Tables wait until 2nd year Graphs Basic idea: A self-referential data structure with nodes referring to any other node in the structure. Nodes can refer to themselves, other nodes, etc. Trees Basic idea: A self-referrential data structure with 0..n (n=2, typically, but not always) links. For binary (n=2) trees A node can be empty or It has a value and two sons (left, right) which refer to trees. Hash Tables Often have collections in which add/search operations are common, but delete operations (rarely) happen Can we build a data structure that is optimized for add/search, but which are (less) efficient for delete? Basic Idea S uppose we have a collection of keys that we need to keep in a list Few deletes Know (rough) number of items that we will have to deal with (<N) Then we define an efficient function f(key) Maps onto 0..N-1 Ideally maps each key onto a different i Basic Idea 2 Hash function maps keys to buckets Ideally, each key maps to a unique bucket It may not happen => collision Have to resolve collisions Many different possibilities We do one here. Other techniques may work better for you. 8
9 Has hing S tart with a list keys[i] = null Insertion Given key, compute hash=f(key). S tarting at keys[hash], find first null entry and set keys[i]=key Associate a value with the key Lookup Given key, compute hash=f(key) S tarting at keys[hash], search until either keys[i] = key (found) or keys[i]=null (not found) Other techniques possible (J ava uses one) Deleting Can t set hash[i]=null Breaks other hash functions S o set hash[i]=invalid Basically waste the space Rehas hing When the table gets full (or nearly full) Rehash the data into a larger table Very expensive Avoid when possible Doing things with Has htables If deletes don t happen often, and n is not too large, this is the way to go. Extremely efficient Trades off space (empty space in table) for time. Much work has gone into the design of good hash functions java.util.has htable HashTable ht = new Hashtable(); ht.put( one, new Integer(1)); ht.put( two, new Integer(2)); ht.put( three, new Integer(3)); Integer n = (Integer) ht.get( three ); Collis ions J ava.util.hashtable uses buckets which are searched sequentially Aka a linked list 9
10 Maps, etc. J ust as J ava has Vector s and ArrayLists Has HashTable s and Map s Worth looking at the API of same Take home message Data structures should be part of your programming toolbox No perfect data structure Different tasks require different structures 1030 has covered a small number of them 2nd year will provide more Read Chapter 19 Summary Work on Assignment #3 Make sure you understand how a linked list works (insertion/deletion in/from different positions) Check the registrar s web site for exam details 10
COMP250: Stacks. Jérôme Waldispühl School of Computer Science McGill University. Based on slides from (Goodrich & Tamassia, 2004)
COMP250: Stacks Jérôme Waldispühl School of Computer Science McGill University Based on slides from (Goodrich & Tamassia, 2004) 2004 Goodrich, Tamassia The Stack ADT A Stack ADT is a list that allows only
More information1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University
Chapter 5: Stacks, ueues and Deques Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,
More informationCH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES
CH4.2-4.3. ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER
More informationThe Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.
The Stack ADT Stacks Set of objects in which the location an item is inserted and deleted is prespecified Stacks! Insert in order! Delete most recent item inserted! LIFO - last in, first out Stacks 2 The
More informationADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )
ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) Unit - 2 By: Gurpreet Singh Dean Academics & H.O.D. (C.S.E. / I.T.) Yamuna Institute of Engineering & Technology, Gadholi What is a Stack? A stack is a
More informationADT Stack. Inserting and deleting elements occurs at the top of Stack S. top. bottom. Stack S
Stacks Stacks & Queues A linear sequence, or list, is an ordered collection of elements: S = (s 1, s 2,..., s n ) Stacks and queues are finite linear sequences. A Stack is a LIFO (Last In First Out) list.
More informationOutline and Reading. The Stack ADT ( 4.2.1) Applications of Stacks ( 4.2.3) Array-based implementation ( 4.2.2) Growable array-based stack.
Stacks Outline and Reading The Stack ADT ( 4.2.1) Applications of Stacks ( 4.2.3) Array-based implementation ( 4.2.2) Growable array-based stack Stacks 2 Abstract Data Types (ADTs) An abstract data type
More informationOutline and Reading. The Stack ADT ( 2.1.1) Applications of Stacks ( 2.1.1) Array-based implementation ( 2.1.1) Growable array-based stack ( 1.
Stacks Outline and Reading The Stack ADT ( 2.1.1) Applications of Stacks ( 2.1.1) Array-based implementation ( 2.1.1) Growable array-based stack ( 1.5) Stacks 2 Abstract Data Types (ADTs) An abstract data
More informationStandard ADTs. Lecture 19 CS2110 Summer 2009
Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2
More informationData Structures Lecture 5
Fall 2017 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 5 Announcement Project Proposal due on Nov. 9 Remember to bring a hardcopy
More informationFoundations of Data Structures
Foundations of Data Structures Lecture 4 Elementary Abstract Data Types (ADT): Stack Queue 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies:
More informationStacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011
Stacks (5.1) CSE 2011 Winter 2011 26 January 2011 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error
More informationHOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS
HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS SYLLABUS ABSTRACT DATA TYPES (ADTS) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations
More informationCSC 321: Data Structures. Fall 2012
CSC 321: Data Structures Fall 2012 Lists, stacks & queues Collection classes: List (ArrayList, LinkedList), Set (TreeSet, HashSet), Map (TreeMap, HashMap) ArrayList performance and implementation LinkedList
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures
Computer Science 210 Data Structures Siena College Fall 2018 Topic Notes: Linear Structures The structures we ve seen so far, Vectors/ArrayLists and linked list variations, allow insertion and deletion
More informationStacks Fall 2018 Margaret Reid-Miller
Stacks 15-121 Fall 2018 Margaret Reid-Miller Today Exam 2 is next Tuesday, October 30 Today: Quiz 5 solutions Recursive add from last week (see SinglyLinkedListR.java) Stacks ADT (Queues on Thursday) ArrayStack
More informationLecture 3 Linear Data Structures: Arrays, Array Lists, Stacks, Queues and Linked Lists
Lecture 3 Linear Data Structures: Arrays, Array Lists, Stacks, Queues and Linked Lists Chapters 3.1-3.3, 5.1-5.2, 6.1-1 - Core Collection Interfaces - 2 - The Java Collections Framework Interface Abstract
More informationcsci 210: Data Structures Stacks and Queues
csci 210: Data Structures Stacks and Queues 1 Summary Topics Stacks and Queues as abstract data types ( ADT) Implementations arrays linked lists Analysis and comparison Applications: searching with stacks
More informationStacks Goodrich, Tamassia
Stacks Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error conditions associated with operations Example:
More informationRecap. List Types. List Functionality. ListIterator. Adapter Design Pattern. Department of Computer Science 1
COMP209 Object Oriented Programming Container Classes 3 Mark Hall List Functionality Types List Iterator Adapter design pattern Adapting a LinkedList to a Stack/Queue Map Functionality Hashing Performance
More informationStacks Goodrich, Tamassia, Goldwasser Stacks
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 Stacks Stacks 1 The Stack ADT The Stack ADT
More informationChapter 2. Stack & Queues. M hiwa ahmad aziz
. Chapter 2 Stack & Queues www.raparinweb.com M hiwa ahmad aziz 1 Stack A stack structure with a series of data elements that Allows access to only the last item inserted. An item is inserted or removed
More informationQueues Fall 2018 Margaret Reid-Miller
Queues 15-121 Fall 2018 Margaret Reid-Miller Today Exam 2 is next Tuesday, October 30 Writing methods various classes that implement Lists. Methods using Lists and Big-O w/ ArrayList or LinkedLists Prove
More informationLecture Data Structure Stack
Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards
More informationLecture 3 Linear Data Structures
Lecture 3 Linear Data Structures Chapters 3.1-3.3, 5.1-5.2, 6.1-1 - Outline Our goal in this lecture is to Review the basic linear data structures Demonstrate how each can be defined as an Abstract Data
More informationCSE 143. Lecture 4: Stacks and Queues
CSE 143 Lecture 4: Stacks and Queues Stacks and queues Sometimes it is good to have a collection that is less powerful, but is optimized to perform certain operations very quickly. Today we will examine
More informationStacks, Queues (cont d)
Stacks, Queues (cont d) CSE 2011 Winter 2007 February 1, 2007 1 The Adapter Pattern Using methods of one class to implement methods of another class Example: using List to implement Stack and Queue 2 1
More informationCSC 321: Data Structures. Fall 2013
CSC 321: Data Structures Fall 2013 Lists, stacks & queues Collection classes: List (ArrayList, LinkedList), Set (TreeSet, HashSet), Map (TreeMap, HashMap) ArrayList performance and implementation LinkedList
More informationStack Abstract Data Type
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 how Java implements a stack To learn how to implement a
More informationQueues COL 106. Slides by Amit Kumar, Shweta Agrawal
Queues COL 106 Slides by Amit Kumar, Shweta Agrawal The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out (FIFO) scheme Insertions are at the rear
More informationPA3 Design Specification
PA3 Teaching Data Structure 1. System Description The Data Structure Web application is written in JavaScript and HTML5. It has been divided into 9 pages: Singly linked page, Stack page, Postfix expression
More informationKeeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10
Keeping Order:! Stacks, Queues, & Deques 1 Stacks 2 Stacks A stack is a last in, first out (LIFO) data structure Primary Operations: push() add item to top pop() return the top item and remove it peek()
More informationStack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack.
STACK Stack ADT 2 A stack is an abstract data type based on the list data model All operations are performed at one end of the list called the top of the stack (TOS) LIFO (for last-in first-out) list is
More information-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed "stack method of expression evaluation" in 1955.
Topic 15 Implementing and Using "stack n. The set of things a person has to do in the future. "I haven't done it yet because every time I pop my stack something new gets pushed." If you are interrupted
More informationLecture 3 Linear Data Structures
Lecture 3 Linear Data Structures - 1 - Learning Outcomes Based on this lecture, you should: Know the basic linear data structures Be able to express each as an Abstract Data Type (ADT) Be able to specify
More informationCS/CE 2336 Computer Science II
CS/CE 2336 Computer Science II UT D Session 11 OO Data Structures Lists, Stacks, Queues Adapted from D. Liang s Introduction to Java Programming, 8 th Ed. 2 What is a Data Structure? A collection of data
More informationBasic Data Structures
Basic Data Structures Some Java Preliminaries Generics (aka parametrized types) is a Java mechanism that enables the implementation of collection ADTs that can store any type of data Stack s1
More informationEC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3
UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between
More informationAn Introduction to Data Structures
An Introduction to Data Structures Advanced Programming ICOM 4015 Lecture 17 Reading: Java Concepts Chapter 20 Fall 2006 Adapded from Java Concepts Companion Slides 1 Chapter Goals To learn how to use
More informationBasic Data Structures 1 / 24
Basic Data Structures 1 / 24 Outline 1 Some Java Preliminaries 2 Linked Lists 3 Bags 4 Queues 5 Stacks 6 Performance Characteristics 2 / 24 Some Java Preliminaries Generics (aka parametrized types) is
More informationAbstract Data Types (ADTs) Queues & Priority Queues. Sets. Dictionaries. Stacks 6/15/2011
CS/ENGRD 110 Object-Oriented Programming and Data Structures Spring 011 Thorsten Joachims Lecture 16: Standard ADTs Abstract Data Types (ADTs) A method for achieving abstraction for data structures and
More informationList ADT. Announcements. The List interface. Implementing the List ADT
Announcements Tutoring schedule revised Today s topic: ArrayList implementation Reading: Section 7.2 Break around 11:45am List ADT A list is defined as a finite ordered sequence of data items known as
More informationStacks. Lecture6: Stacks. Stack Operations. Stack Interface in Java
Stacks (01F) Lecture6: Stacks What is stack? An abstract data type storing arbitrary objects. An ordered list in which all insertions and deletions are made at one end, called top Push Pop Top Bohyung
More informationCS 231 Data Structures and Algorithms Fall DDL & Queue Lecture 20 October 22, Prof. Zadia Codabux
CS 231 Data Structures and Algorithms Fall 2018 DDL & Queue Lecture 20 October 22, 2018 Prof. Zadia Codabux 1 Agenda Mid Semester Analysis Doubly Linked List Queue 2 Administrative None 3 Doubly Linked
More informationCPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues
CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.
More informationLecture 4 Stack and Queue
Lecture 4 Stack and Queue Bo Tang @ SUSTech, Spring 2018 Our Roadmap Stack Queue Stack vs. Queue 2 Stack A stack is a sequence in which: Items can be added and removed only at one end (the top) You can
More information15. Stacks and Queues
COMP1917 15s2 15. Stacks and Queues 1 COMP1917: Computing 1 15. Stacks and Queues Reading: Moffat, Section 10.1-10.2 Overview Stacks Queues Adding to the Tail of a List Efficiency Issues Queue Structure
More informationStacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)
Outline stacks stack ADT method signatures array stack implementation linked stack implementation stack applications infix, prefix, and postfix expressions 1 Stacks stacks of dishes or trays in a cafeteria
More informationCS212:Data Structure
C212:Data tructure Direct applications Page-visited history in a Web browser Undo sequence in a text editor Chain of method calls in the Java Virtual Machine Indirect applications Auxiliary data structure
More informationDEEPIKA KAMBOJ UNIT 2. What is Stack?
What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you
More informationStacks Goodrich, Tamassia Stacks
Stacks Stacks 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error conditions associated with operations
More informationCSE 131 Computer Science 1 Module 9a: ADT Representations. Stack and queue ADTs array implementations Buffer ADT and circular lists
CSE 11 Computer Science 1 Module 9a: ADT Representations Stack and queue ADTs array implementations Buffer ADT and circular lists Buffer ADT add and remove from both ends»can grow and shrink from either
More informationITI Introduction to Computing II
index.pdf March 17, 2013 1 ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 17, 2013 Definitions A List is a linear abstract
More informationCMSC 132: Object-Oriented Programming II. Stack and Queue
CMSC 132: Object-Oriented Programming II Stack and Queue 1 Stack Allows access to only the last item inserted. An item is inserted or removed from the stack from one end called the top of the stack. This
More informationBuilding Java Programs
Building Java Programs Appendix Q Lecture Q-1: stacks and queues reading: appendix Q 2 Runtime Efficiency (13.2) efficiency: measure of computing resources used by code. can be relative to speed (time),
More informationinfix expressions (review)
Outline infix, prefix, and postfix expressions queues queue interface queue applications queue implementation: array queue queue implementation: linked queue application of queues and stacks: data structure
More informationCMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1
CMSC 341 Linked Lists, Stacks and Queues CMSC 341 Lists, Stacks &Queues 1 Goal of the Lecture To complete iterator implementation for ArrayList Briefly talk about implementing a LinkedList Introduce special
More informationCOSC This week. Cloning. Cloning: Be Cautious. Cloning: the wrong type. Cloning: use super.clone()
This week COSC 3.3 Week 7, February 3, 4. Read chapter 3 Prepare for midterm on Thursday, Feb. 6 9:-: No aids (no calculators, aid sheet, etc) S ome multiple choice, some short answer, and a large programming
More information1.00 Lecture 26. Data Structures: Introduction Stacks. Reading for next time: Big Java: Data Structures
1.00 Lecture 26 Data Structures: Introduction Stacks Reading for next time: Big Java: 19.1-19.3 Data Structures Set of primitives used in algorithms, simulations, operating systems, applications to: Store
More informationJava Collections. Readings and References. Collections Framework. Java 2 Collections. CSE 403, Spring 2004 Software Engineering
Readings and References Java Collections "Collections", Java tutorial http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Spring 2004 Software Engineering http://www.cs.washington.edu/education/courses/403/04sp/
More informationArray Lists Outline and Required Reading: Array Lists ( 7.1) CSE 2011, Winter 2017, Section Z Instructor: N. Vlajic
rray Lists Outline and Required Reading: rray Lists ( 7.) CSE 20, Winter 207, Section Z Instructor: N. Vlajic Lists in Everyday Life 2 List convenient way to organize data examples: score list, to-do list,
More informationNotes on access restrictions
Notes on access restrictions A source code file MyClass.java is a compilation unit and can contain at most one public class. Furthermore, if there is a public class in that file, it must be called MyClass.
More informationGenerics. IRS W-9 Form
Generics IRS W-9 Form Generics Generic class and methods. BNF notation Syntax Non-parametrized class: < class declaration > ::= "class" < identifier > ["extends" < type >] ["implements" < type list >]
More informationCSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,
CSE 143 Lecture 26 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, 15.3-15.4, 16.4-16.5 slides created by Marty Stepp, adapted by Alyssa Harding
More informationLecture 3: Stacks & Queues
Lecture 3: Stacks & Queues Prakash Gautam https://prakashgautam.com.np/dipit02/ info@prakashgautam.com.np 22 March, 2018 Objectives Definition: Stacks & Queues Operations of Stack & Queues Implementation
More informationData Structures and Algorithms Notes
Data Structures and Algorithms Notes Notes by Winst Course taught by Dr. G. R. Baliga 256-400 ext. 3890 baliga@rowan.edu Course started: September 4, 2012 Last generated: December 18, 2013 Interfaces -
More informationTopic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1
Topic #9: Collections CSE 413, Autumn 2004 Programming Languages http://www.cs.washington.edu/education/courses/413/04au/ If S is a subtype of T, what is S permitted to do with the methods of T? Typing
More informationDataStruct 5. Stacks, Queues, and Deques
2013-2 DataStruct 5. Stacks, Queues, and Deques Michael T. Goodrich, et. al, Data Structures and Algorithms in C++, 2 nd Ed., John Wiley & Sons, Inc., 2011. October 30, 2013 Advanced Networking Technology
More informationData structure and algorithm in Python
Data structure and algorithm in Python Stacks, Queues and Deques Xiaoping Zhang School of Mathematics and Statistics, Wuhan University Table of contents 1. Stacks 2. Queue 3. Double-Ended Queues 1 Stacks
More informationWentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.
Lecture 11 1 More Data Structures In this lecture we will use a linked list to implement two abstract data types (ADT) An ADT provides the interface, or what a data structure does We can then use code
More informationCPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues
CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 available very
More informationSTACKS AND QUEUES. Problem Solving with Computers-II
STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()
More informationdata structures and algorithms lecture 6
data structures and algorithms 2017 09 21 lecture 6 overview lower bound counting sort radix sort stacks queues material question we have seen for example insertion sort: worst-case in O(n 2 ) merge sort:
More informationCOS 226 Algorithms and Data Structures Fall Midterm
COS 226 Algorithms and Data Structures Fall 2017 Midterm This exam has 10 questions (including question 0) worth a total of 55 points. You have 0 minutes. This exam is preprocessed by a computer, so please
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Abstract Data Type Stack Version of February 2, 2013 Abstract These lecture notes are meant
More informationStacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle.
Stacks 1 Stacks The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle. 2 Main stack operations Insertion and removal are defined by: push(e): inserts
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 07 / 26 / 2016 Instructor: Michael Eckmann Today s Topics Comments/Questions? Stacks and Queues Applications of both Priority Queues Michael Eckmann - Skidmore
More informationAbstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1
Abstract Data Types Stack January 26, 2018 Cinda Heeren / Geoffrey Tien 1 Abstract data types and data structures An Abstract Data Type (ADT) is: A collection of data Describes what data are stored but
More informationLecture 2: Stacks and Queues
Lecture 2: Stacks and Queues CSE 373: Data Structures and Algorithms CSE 373 19 WI - KASEY CHAMPION 1 Warm Up 1. Grab a worksheet 2. Introduce yourself to your neighbors J 3. Discuss the answers 4. Log
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Abstract Data Type Stack Version of February 2, 2013 Abstract These lecture notes are meant
More informationLists and Iterators. CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology
Lists and Iterators CSSE 221 Fundamentals of Software Development Honors Rose-Hulman Institute of Technology Announcements Should be making progress on VectorGraphics. Should have turned in CRC cards,
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures
Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Linear Structures The structures we ve seen so far, Vectors/ArrayLists and linked lists, allow insertion and deletion of elements
More informationLab 7 1 Due Thu., 6 Apr. 2017
Lab 7 1 Due Thu., 6 Apr. 2017 CMPSC 112 Introduction to Computer Science II (Spring 2017) Prof. John Wenskovitch http://cs.allegheny.edu/~jwenskovitch/teaching/cmpsc112 Lab 7 - Using Stacks to Create a
More informationLecture 3 Linear Data Structures
Lecture 3 Linear Data Structures - 1 - Learning Outcomes Based on this lecture, you should: Know the basic linear data structures Be able to express each as an Abstract Data Type (ADT) Be able to specify
More informationAdam Blank Lecture 5 Winter 2015 CSE 143. Computer Programming II
Adam Blank Lecture 5 Winter 2015 CSE 143 Computer Programming II CSE 143: Computer Programming II Stacks & Queues Questions From Last Time 1 Can we include implementation details in the inside comments
More informationStacks and Queues. David Greenstein Monta Vista
Stacks and Queues David Greenstein Monta Vista Stack vs Queue Stacks and queues are used for temporary storage, but in different situations Stacks are Used for handling nested structures: processing directories
More informationn Data structures that reflect a temporal relationship q order of removal based on order of insertion n We will consider:
Linear, time-ordered structures CS00: Stacks n Prichard Ch 7 n Data structures that reflect a temporal relationship order of removal based on order of insertion n We will consider: first come,first serve
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Queues ArrayQueue Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 10, 2014 Abstract These lecture notes are meant to be looked
More informationSummer Final Exam Review Session August 5, 2009
15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding
More informationCSC148 Week 2. Larry Zhang
CSC148 Week 2 Larry Zhang 1 Admin Discussion board is up (link on the course website). 2 Outline for this week Abstract Data Type Stack Queue 3 Abstract Data Type (ADT) 4 What is an abstract data type
More informationCSC148H Week 3. Sadia Sharmin. May 24, /20
CSC148H Week 3 Sadia Sharmin May 24, 2017 1/20 Client vs. Developer I For the first couple of weeks, we have played the role of class designer I However, you are also often in the opposite role: when a
More informationImplementing Lists, Stacks, Queues, and Priority Queues
Implementing Lists, Stacks, Queues, and Priority Queues CSE260, Computer Science B: Honors Stony Brook University http://www.cs.stonybrook.edu/~cse260 1 Objectives To design common features of lists in
More informationLecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this
Lecture Notes Array Review An array in C++ is a contiguous block of memory. Since a char is 1 byte, then an array of 5 chars is 5 bytes. For example, if you execute the following C++ code you will allocate
More informationCMPS 390 Data Structures
CMPS 390 Data Structures Programming Assignment #02 Infix to Postfix 1. Complete two methods in Java program (Postfix.java) to convert an infix expression into a postfix expression and evaluate the postfix
More informationLinear Data Structures
Linear Data Structures Arrays Arrays are stored in contiguous memory locations and contain similar data An element can be accessed, inserted or removed by specifying its position (number of elements preceding
More informationTop of the Stack. Stack ADT
Module 3: Stack ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Stack ADT Features (Logical View) A List that
More informationStacks. Access to other items in the stack is not allowed A LIFO (Last In First Out) data structure
CMPT 225 Stacks Stacks A stack is a data structure that only allows items to be inserted and removed at one end We call this end the top of the stack The other end is called the bottom Access to other
More informationElementary Data Structures. Stacks, Queues, & Lists Amortized analysis Trees
Elementary Data Structures Stacks, Queues, & Lists Amortized analysis Trees The Stack ADT ( 2.1.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in first-out scheme Think
More informationInsertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue
Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,
More informationInterfaces & Generics
Interfaces & Generics CSC207 Winter 2018 The Programming Interface The "user" for almost all code is a programmer. That user wants to know:... what kinds of object your class represents... what actions
More information