CE204 Data Structures and Algorithms Part 2

Size: px
Start display at page:

Download "CE204 Data Structures and Algorithms Part 2"

Transcription

1 CE204 Data Structures and Algorithms Part 2 14/01/2018 CE204 Part 2 1

2 Abstract Data Types 1 An abstract data type is a type that may be specified completely without the use of any programming language. To specify an abstract data type we need to provide: a name for the type the names of the primitive operations that can be performed on the type, and their argument and result types the semantics of the operations, i.e. a description of how they behave 14/01/2018 CE204 Part 2 2

3 Abstract Data Types 2 If an abstract data type (ADT) has been fully specified an application program should be able to make use of the type without knowing how it has been implemented. For example, a stack may be implemented using an array or a linked list (or other alternatives) but a programmer should know what the effect of a statement such as push(7, mystack); or mystack.push(7); will be without needing to know which representation has been chosen. 14/01/2018 CE204 Part 2 3

4 Abstract Data Types 3 To guarantee that an application will work even if the representation of the ADT is changed the application must access objects of the ADT only by means of the primitive operations. If possible the implementer of the ADT should write his program in a manner that makes it impossible for an application to access objects other than by using the primitive operations; in Java we can do this by making the instance variables (i.e. the data in the object) private. 14/01/2018 CE204 Part 2 4

5 The Stack ADT 1 A stack is a last-in-first-out data store, which can only be accessed from the top. The essential primitive operations for the stack ADT are push, which adds an item to the top of the stack pop, which removes the top item top, which returns the top item. In addition we need to provide an operation to create an empty stack and an operation isempty to determine whether a stack is empty. 14/01/2018 CE204 Part 2 5

6 The Stack ADT 2 The following axioms give a semantics to the operations isempty(createstack()) = true isempty(push(n, s)) = false top(push(n, s)) = n pop(push(n, s)) = s In these axioms s refers to the state of a stack before operations are applied, so, for example, the last axiom states that the result of applying pop to the result of pushing n onto s is that the stack will be back in its starting state. 14/01/2018 CE204 Part 2 6

7 The Stack ADT 3 Note that the axioms on the previous slide assume a procedural approach in which, for example, the push operation takes as arguments a data item and a stack and returns as its result the new state of the stack. In an object-oriented implementation push would be a one-argument method to be applied to a Stack object. Also note that the axioms do not describe the behaviour in error situations such as an attempt to examine the top item in a empty stack. 14/01/2018 CE204 Part 2 7

8 Implementing Stacks in Java 1 There are many possible ways to implement the stack ADT in Java since all should behave in the same way and support the same primitive operations we can write an interface that all approaches should implement. public interface Stack<T> { public boolean isempty(); public void push(t x); public void pop(); public T top(); 14/01/2018 CE204 Part 2 8

9 Implementing Stacks in Java 2 Our interface did not specify an operation to create a new empty stack implementations will simply use a constructor to ensure that all newly-created Stack objects are empty. Exceptions should be thrown if attempts are made to apply pop or top to an empty stack. Hence we need a StackException class this is presented on the next slide. We choose to extend RuntimeException so that throws clauses will not be needed. 14/01/2018 CE204 Part 2 9

10 Implementing Stacks in Java 3 public class StackException extends RuntimeException { public StackException(String s) { super("attempted to apply " + s + " to empty stack"); 14/01/2018 CE204 Part 2 10

11 Implementing Stacks Using Arrays 1 The simplest way to implement stacks is to store the elements in an array. To avoid having to shift elements when items are added or removed we choose to have the bottom of the stack at the beginning of the array, so it is necessary to keep track of the position of the top item, using an integer variable, usually referred to as a cursor. An initial size for the array must be chosen; if the array becomes full it will be necessary to copy its contents into a new larger array and make the instance variable inside the stack object refer to this new array. 14/01/2018 CE204 Part 2 11

12 Implementing Stacks Using Arrays 2 A complication arises in the constructor for the stack we need to initialise the array variable to refer to a new array of objects of type T but a statement such as arr = new T[20]; is not allowed when T is a type parameter. Hence it is necessary to create a new array of objects of type Object and then downcast it to type T[]. Normally we could not downcast in this way since an array of objects of type Object is not an array of objects of type T, but this kind of downcast is allowed when a new array of objects is created. 14/01/2018 CE204 Part 2 12

13 Implementing Stacks Using Arrays 3 public class ArrayStack<T> implements Stack<T> { private T[] arr; private int cursor; public ArrayStack() { arr = (T[])new Object[20]; cursor = -1; public boolean isempty() { return (cursor==-1); // class continued on next slide 14/01/2018 CE204 Part 2 13

14 Implementing Stacks Using Arrays 4 // class ArrayStack<T> continued public T top() { if (cursor==-1) throw new StackException("top"); return arr[cursor]; public void pop() { if (cursor==-1) throw new StackException("pop"); arr[cursor] = null; // not essential cursor--; // class continued on next slide 14/01/2018 CE204 Part 2 14

15 Implementing Stacks Using Arrays 5 // class ArrayStack<T> continued public void push(t x) { cursor++; if (cursor==arr.length) { T[] temp = (T[])new Object[arr.length+20]; for (int i = 0; i<arr.length; i++) temp[i] = arr[i]; arr = temp; arr[cursor] = x; 14/01/2018 CE204 Part 2 15

16 Implementing Stacks Using Arrays 6 We might wish to provide an extra constructor which takes an initial array size as an argument. If a programmer wants to print the contents of his stack when debugging his program the only way he could do this using the primitive operations would be to pop all of the items, which would affect the subsequent behaviour of the program. Hence we should also provide in the ArrayStack class a tostring method. 14/01/2018 CE204 Part 2 16

17 Implementing Stacks Using Arrays 7 As an alternative to a direct implementation using arrays we could use an ArrayList or Vector object to store the items. Taking this approach a cursor is not needed since we can calculate the location of the top item using the size method from the Collection interface. Since these classes automatically generate a bigger array when the current one is full the push method becomes much simpler. A complete implementation is presented on the following slides. 14/01/2018 CE204 Part 2 17

18 Implementing Stacks Using Arrays 8 public class ALStack<T> implements Stack<T> { private ArrayList<T> al; public ALStack() { al = new ArrayList<T>(20); public boolean isempty() { return (al.isempty()); public void push(t x) { al.add(x); // adds to end of list // class continued on next slide 14/01/2018 CE204 Part 2 18

19 Implementing Stacks Using Arrays 9 // class ALStack<T> continued public T top() { if (al.isempty()) throw new StackException("top"); return al.get(al.size()-1); public void pop() { if (al.isempty()) throw new StackException("pop"); al.remove(al.size()-1); 14/01/2018 CE204 Part 2 19

20 Implementing Stacks Using Linked Lists 1 Array-based implementations of stacks suffer from the disadvantage of having to select an array size. If the array is too large memory space may be wasted, whereas if the array is too small performance may be affected by the need to copy the contents into a larger array. These disadvantages can be overcome by using linked lists since cells are created as the items are added the size of the list will be precisely the size of the stack. We can choose to use the LinkedList class from the collections framework or create a linked list of ListCell objects as seen in part 1 of the slides. 14/01/2018 CE204 Part 2 20

21 Implementing Stacks Using Linked Lists 2 Since the LinkedList class has methods to add, remove and access items at both ends it does not matter which end of the linked list is the top of the stack when using the class to implement stacks. On the following slides we present a version that uses the front of the list as the top of the stack to use the back of the list we would simply use methods such as addlast instead of methods such as addfirst. Since the linked-list class uses doubly-linked lists the performance should not be affected. 14/01/2018 CE204 Part 2 21

22 Implementing Stacks Using Linked Lists 3 public class LLStack<T> implements Stack<T> { private LinkedList<T> ll; public LLStack() { ll = new LinkedList<T>(); public boolean isempty() { return (ll.isempty()); public void push(t x) { ll.addfirst(x); // class continued on next slide 14/01/2018 CE204 Part 2 22

23 Implementing Stacks Using Linked Lists 4 // class LLStack<T> continued public T top() { if (ll.isempty()) throw new StackException("top"); return ll.getfirst(); public void pop() { if (ll.isempty()) throw new StackException("pop"); ll.removefirst(); 14/01/2018 CE204 Part 2 23

24 Implementing Stacks Using Linked Lists 5 If we choose to implement stacks by building a singly-linked list from ListCell objects we should use the front of the list as the top of the stack in order to ensure that all of the operations can be implemented efficiently (since, if we choose to maintain a reference to the last item in the list, we cannot update this when removing the last item without traversing the list, and if we choose not to maintain such a reference, we cannot quickly access the last item). The implementation using the front of the list as the top of the stack is easy and efficient so there is no benefit to be gained from attempting to implement our own doubly-linked lists. 14/01/2018 CE204 Part 2 24

25 Implementing Stacks Using Linked Lists 6 public class ListStack<T> implements Stack<T> { private ListCell<T> topcell; // ListCell<T> is declared on part 1 slide 23 public ListStack() { topcell = null; public boolean isempty() { return (topcell==null); public void push(t x) { topcell = new ListCell<T>(x, topcell); // class continued on next slide 14/01/2018 CE204 Part 2 25

26 Implementing Stacks Using Linked Lists 7 // class ListStack<T> continued public T top() { if (topcell==null) throw new StackException("top"); return topcell.data; public void pop() { if (topcell==null) throw new StackException("pop"); topcell = topcell.next; 14/01/2018 CE204 Part 2 26

27 Deciding Which Implementation to Use 1 We have seen four different classes that implement the stack interface. In most cases the choice of which to use will not be very important. If there is a single stack and it is not expected to grow very large an array implementation may be chosen since a full array will require less memory space than a linked list containing the same items. If however there are several stacks and it is not known which is likely to become large the unused space in arrays may result in inefficient memory usage so a linked-list implementation may be preferred. 14/01/2018 CE204 Part 2 27

28 Deciding Which Implementation to Use 2 The use of classes from the collections interface will usually simplify the coding of an abstract data type, but in the case of a simple type such as a stack this is not very significant. Direct implementations are likely to be a little more efficient since the overheads involved with calling library methods are avoided. Space may also be saved in particular the use of the LinkedList class will require about 50% more space than the ListCell version since the library class is doubly-linked. In languages without extensive libraries the use of direct implementations may be necessary so it is useful to know how to produce them. 14/01/2018 CE204 Part 2 28

29 The Queue ADT 1 A queue is similar to a stack, but instead of adding and removing items at the same end items are added at the back and removed from the front. The essential primitive operations for the queue ADT are add, which adds an item to the back of the queue removefront, which removes the front item front, which returns the front item isempty, to determine whether a queue is empty Unlike stacks there is no universal convention for the naming of the operations for example, some authors use the names enqueue and dequeue for the addition and removal operations. 14/01/2018 CE204 Part 2 29

30 The Queue ADT 2 The following axioms give a semantics to the operations isempty(createqueue()) = true isempty(add(n, q)) = false front(add(n, q)) = n, if q is empty front(add(n, q)) = front(q), if q is not empty removefront(add(n, q)) = q, if q is empty removefront(add(n, q)) = add(n, removefront(q)), if q is not empty 14/01/2018 CE204 Part 2 30

31 Implementing Queues in Java As with stacks there are several possible ways to implement the queue ADT in Java; again we can write an interface that all approaches should implement. public interface Queue<T> { public boolean isempty(); public void add(t x); public void removefront(); public T front(); 14/01/2018 CE204 Part 2 31

32 Implementing Queues Using Arrays 1 We first consider an array-based implementation of the queue ADT. If the first element of the array holds the back item of the queue it would be necessary to shift elements each time an item is added. On the other hand, if the first element holds the front of the queue it would be necessary to shift elements each time the front item is removed. To avoid any need for shifting the normal approach is to let the queue move along the array. Hence we need two cursors, frontpos and backpos to keep track of the positions of both the front and back items. 14/01/2018 CE204 Part 2 32

33 Implementing Queues Using Arrays 2 Observe that for a queue with just one element we would have frontpos==backpos. Removing an item from a queue causes frontpos to be incremented so after removing the element from a queue with only one element we will have frontpos==backpos+1. Hence this is the condition that indicates an empty queue. Adding an element to a queue causes backpos to be incremented; after adding the first element to a newly-created queue we expect both frontpos and backpos to be 0 so the initial values given to these variables in the constructor should be 0 and 1. 14/01/2018 CE204 Part 2 33

34 Implementing Queues Using Arrays 3 public class ArrayQueue<T> implements Queue<T> { private T[] arr; private int frontpos, backpos; public ArrayQueue() { arr = (T[])new Object[20]; frontpos = 0; backpos = -1; public boolean isempty() // first attempt { return frontpos==backpos+1; // more methods needed 14/01/2018 CE204 Part 2 34

35 Implementing Queues Using Arrays 4 After a series of insertions and deletions the movement of the queue means that the end of the array would soon be reached. We could shift the contents of the queue back to the start of the array when this happens, but it is more efficient to treat the array as if it were circular and reuse location 0. Hence when incrementing and comparing the cursors we need to perform the operations modulo the size of the array, using the % operator. (Recall that a%b gives the remainder when a is divided by b.) 14/01/2018 CE204 Part 2 35

36 Implementing Queues Using Arrays 5 // some methods for ArrayQueue<T> class public boolean isempty() { return frontpos==(backpos+1)%arr.length; public T front() { if (frontpos==(backpos+1)%arr.length) throw new QueueException("front"); return arr[frontpos]; public void removefront() { if (frontpos==(backpos+1)%arr.length) throw new QueueException("removeFront"); frontpos = (frontpos+1)%arr.length; 14/01/2018 CE204 Part 2 36

37 Implementing Queues Using Arrays 6 If the array were to become full backpos+1 would be equal to frontpos (modulo the size of the array); this is the same as the condition for an empty queue, so there would be no way to distinguish between a full array and an empty queue. Hence we need to limit the number of items that can be stored in an array to one less than the size of the array, and copy the contents of the queue into a larger array as soon as the array becomes full instead of waiting until an attempt is made to add another element. The coding of the add method is left as an exercise. 14/01/2018 CE204 Part 2 37

38 Implementing Queues Using Arrays 7 The ArrayList class does not provide support for the circular view of arrays needed for an efficient array implementation of queues, so any attempt to provide an ArrayList implementation would require more complicated coding than the array implementation and provide no benefits. Hence such an approach should not be considered. 14/01/2018 CE204 Part 2 38

39 Implementing Queues Using Linked Lists 1 A LinkedList version of the queue class is easy to implement and is very similar to the linked list version of the stack class. To avoid confusion it is preferable to use the front of the linked list as the front of the queue, but as with the stack class it would be just as simple to use the front of the list as the back of the queue. The complete code for the version using the front of the list as the front of the queue is provided on the following slides. 14/01/2018 CE204 Part 2 39

40 Implementing Queues Using Linked Lists 2 public class LLQueue<T> implements Queue<T> { private LinkedList<T> ll; public LLQueue() { ll = new LinkedList<T>(); public boolean isempty() { return (ll.isempty()); public void add(t x) { ll.addlast(x); // class continued on next slide 14/01/2018 CE204 Part 2 40

41 Implementing Queues Using Linked Lists 3 // class LLQueue<T> continued public T front() { if (ll.isempty()) throw new QueueException("front"); return ll.getfirst(); public void removefront() { if (ll.isempty()) throw new QueueException("removeFront"); ll.removefirst(); 14/01/2018 CE204 Part 2 41

42 Implementing Queues Using Linked Lists 4 As with implementations of stacks, space can be saved and a slight efficiency gain can be achieved by providing a direct implementation using singly-linked lists. In order to be able to implement the removefront method efficiently we need to be able to access a reference to the second item in the queue, so there must be a link from the first item to the second item. Hence the front of the queue needs to be at the head of the list. To efficiently implement the add method we need to access the last item in the linked list, so we need to maintain a reference to this as well as the reference to the first item in the list. 14/01/2018 CE204 Part 2 42

43 Implementing Queues Using Linked Lists 5 Since items will be added to the back of the linked list the next reference of any newly-created list cell will always be null. Hence the constructor for the cell class should take only one argument, the value to be stored, and always initialise the next reference to null. We could add a new one-argument constructor to the ListCell class previously presented, but it is just as simple to write a new class with only a one-argument constructor. The implementation on the following slides uses such a class, called QCell. 14/01/2018 CE204 Part 2 43

44 Implementing Queues Using Linked Lists 6 // ListQueue.java class QCell<T> { T data; QCell<T> next; QCell(T x) { data = x; next = null; // file continued on next slide 14/01/2018 CE204 Part 2 44

45 Implementing Queues Using Linked Lists 7 // ListQueue.java continued public class ListQueue<T> implements Queue<T> { private QCell<T> frontcell, backcell; public ListQueue() { frontcell = backcell = null; public boolean isempty() { return (frontcell==null); // class continued on next slide 14/01/2018 CE204 Part 2 45

46 Implementing Queues Using Linked Lists 8 // class ListQueue<T> continued public T front() { if (frontcell==null) throw new QueueException("front"); return frontcell.data; public void removefront() { if (frontcell==null) throw new QueueException("removeFront"); frontcell = frontcell.next; if (frontcell==null) backcell = null; // class continued on next slide 14/01/2018 CE204 Part 2 46

47 Implementing Queues Using Linked Lists 9 // class ListQueue<T> continued public void add(t x) { QCell<T> newcell = new QCell<T>(x); if (frontcell==null) frontcell = backcell = newcell; else { // order of these statements is important! backcell.next = newcell; backcell = newcell; 14/01/2018 CE204 Part 2 47

Lists, Stacks, and Queues

Lists, Stacks, and Queues Unit 8, Part 2 Lists, Stacks, and Queues Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Representing a Sequence: Arrays vs. Linked Lists Sequence an ordered collection of items (position

More information

CMSC 132: Object-Oriented Programming II. Stack and Queue

CMSC 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 information

CE204 Data Structures and Algorithms Part 1

CE204 Data Structures and Algorithms Part 1 CE204 Data Structures and Algorithms Part 1 11/01/2018 CE204 Part 1 1 Recommended Reading The most useful book for much of the material in this module is Data Structures and Algorithm Analysis in Java

More information

Lists, Stacks, and Queues

Lists, Stacks, and Queues Lists, Stacks, and Queues Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Representing a Sequence: Arrays vs. Linked Lists Sequence an ordered collection of items (position

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 07: Linked Lists MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Linked Lists 2 Introduction Linked List Abstract Data Type SinglyLinkedList ArrayList Keep in Mind Introduction:

More information

ITI Introduction to Computing II

ITI 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 information

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue

Insertions 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 information

Queues. CITS2200 Data Structures and Algorithms. Topic 5

Queues. CITS2200 Data Structures and Algorithms. Topic 5 CITS2200 Data Structures and Algorithms Topic 5 Queues Implementations of the Queue ADT Queue specification Queue interface Block (array) representations of queues Recursive (linked) representations of

More information

Announcements Queues. Queues

Announcements Queues. Queues Announcements. Queues Queues A queue is consistent with the general concept of a waiting line to buy movie tickets a request to print a document crawling the web to retrieve documents A queue is a linear

More information

CS 211 Programming Practicum Spring 2018

CS 211 Programming Practicum Spring 2018 Due: Thursday, 4/5/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

Queues Fall 2018 Margaret Reid-Miller

Queues 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 information

CMPSCI 187: Programming With Data Structures. Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012

CMPSCI 187: Programming With Data Structures. Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012 CMPSCI 187: Programming With Data Structures Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012 Implementing Stacks With Arrays The Idea of the Implementation Data Fields

More information

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES

CH 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 information

Lists. CITS2200 Data Structures and Algorithms. Topic 9

Lists. CITS2200 Data Structures and Algorithms. Topic 9 CITS2200 Data Structures and Algorithms Topic 9 Lists Why lists? List windows Specification Block representation Singly linked representation Performance comparisons Reading: Lambert and Osborne, Sections

More information

Interfaces & Generics

Interfaces & 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

A queue is a linear collection whose elements are added on one end and removed from the other

A queue is a linear collection whose elements are added on one end and removed from the other A queue is consistent with the general concept of a waiting line to buy movie tickets a request to print a document crawling the web to retrieve documents Adding an element Removing an element A queue

More information

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011

Stacks (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 information

CS 211 Programming Practicum Spring 2017

CS 211 Programming Practicum Spring 2017 Due: Tuesday, 3/28/17 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a JAVA program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

Data Structures And Algorithms

Data Structures And Algorithms Data Structures And Algorithms Stacks Eng. Anis Nazer First Semester 2017-2018 Stack An Abstract data type (ADT) Accessed only on one end Similar to a stack of dishes you can add/remove on top of stack

More information

ITI Introduction to Computing II

ITI 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 information

csci 210: Data Structures Stacks and Queues

csci 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 information

CS61B Spring 2016 Guerrilla Section 2 Worksheet

CS61B Spring 2016 Guerrilla Section 2 Worksheet Spring 2016 27 February 2016 Directions: In groups of 4-5, work on the following exercises. Do not proceed to the next exercise until everyone in your group has the answer and understands why the answer

More information

LIFO : Last In First Out

LIFO : Last In First Out Introduction Stack is an ordered list in which all insertions and deletions are made at one end, called the top. Stack is a data structure that is particularly useful in applications involving reversing.

More information

Summer Final Exam Review Session August 5, 2009

Summer 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 information

Data Abstraction and Specification of ADTs

Data Abstraction and Specification of ADTs CITS2200 Data Structures and Algorithms Topic 4 Data Abstraction and Specification of ADTs Example The Reversal Problem and a non-adt solution Data abstraction Specifying ADTs Interfaces javadoc documentation

More information

Queues COL 106. Slides by Amit Kumar, Shweta Agrawal

Queues 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 information

DNHI Homework 3 Solutions List, Stacs and Queues

DNHI Homework 3 Solutions List, Stacs and Queues Solutions List, Stacs and Queues Problem 1 Given the IntegerQueue ADT below state the return value and show the content of the, initially empty, queue of Integer objects after each of the following operations.

More information

CSCD 326 Data Structures I Stacks

CSCD 326 Data Structures I Stacks CSCD 326 Data Structures I Stacks 1 Stack Interface public interface StackInterface { public boolean isempty(); // Determines whether the stack is empty. // Precondition: None. // Postcondition: Returns

More information

Topic 6: Inner Classes

Topic 6: Inner Classes Topic 6: Inner Classes What's an inner class? A class defined inside another class Three kinds: inner classes static nested classes anonymous classes this lecture: Java mechanisms later: motivation & typical

More information

CS 211 Programming Practicum Fall 2018

CS 211 Programming Practicum Fall 2018 Due: Wednesday, 11/7/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 07: Linked Lists and Iterators MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Linked Lists 2 Introduction Linked List Abstract Data Type General Implementation of the ListADT

More information

CSC 1052 Algorithms & Data Structures II: Stacks

CSC 1052 Algorithms & Data Structures II: Stacks CSC 1052 Algorithms & Data Structures II: Stacks Professor Henry Carter Spring 2018 Recap Abstraction allows for information to be compartmentalized and simplifies modular use Interfaces are the Java construction

More information

Queues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1

Queues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Queues October 20, 2017 Hassan Khosravi / Geoffrey Tien 1 Queue ADT Queue ADT should support at least the first two operations: enqueue insert an item to the back of the queue dequeue remove an item from

More information

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10

Keeping 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 information

Queue. COMP 250 Fall queues Sept. 23, 2016

Queue. COMP 250 Fall queues Sept. 23, 2016 Queue Last lecture we looked at a abstract data type called a stack. The two main operations were push and pop. I introduced the idea of a stack by saying that it was a kind of list, but with a restricted

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

Stacks and Queues. David Greenstein Monta Vista

Stacks 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 information

COE 312 Data Structures. Welcome to Exam II Monday November 23, Instructor: Dr. Wissam F. Fawaz

COE 312 Data Structures. Welcome to Exam II Monday November 23, Instructor: Dr. Wissam F. Fawaz 1 COE 312 Data Structures Welcome to Exam II Monday November 23, 2016 Instructor: Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book. Please do not forget to write your name

More information

CS350: Data Structures Stacks

CS350: Data Structures Stacks Stacks James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Stacks Stacks are a very common data structure that can be used for a variety of data storage

More information

Lists. ordered lists unordered lists indexed lists 9-3

Lists. ordered lists unordered lists indexed lists 9-3 The List ADT Objectives Examine list processing and various ordering techniques Define a list abstract data type Examine various list implementations Compare list implementations 9-2 Lists A list is a

More information

Queue rear tail front head FIFO

Queue rear tail front head FIFO The Queue ADT Objectives Examine queue processing Define a queue abstract data type Demonstrate how a queue can be used to solve problems Examine various queue implementations Compare queue implementations

More information

Examination Questions Midterm 1

Examination Questions Midterm 1 CS1102s Data Structures and Algorithms 10/2/2010 Examination Questions Midterm 1 This examination question booklet has 9 pages, including this cover page, and contains 15 questions. You have 40 minutes

More information

CS 231 Data Structures and Algorithms Fall DDL & Queue Lecture 20 October 22, Prof. Zadia Codabux

CS 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 information

CMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011

CMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 CMPSCI 187: Programming With Data Structures Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 Implementing Stacks With Linked Lists Overview: The LinkedStack Class from L&C The Fields and

More information

Stacks and Queues

Stacks and Queues Stacks and Queues 2-25-2009 1 Opening Discussion Let's look at solutions to the interclass problem. Do you have any questions about the reading? Do you have any questions about the assignment? Minute Essays

More information

Implementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations

Implementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations Readings List Implementations Chapter 20.2 Objectives Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations Additional references:

More information

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

Computer 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 information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

CS 61B Spring 2017 Guerrilla Section 3 Worksheet. 25 February 2017

CS 61B Spring 2017 Guerrilla Section 3 Worksheet. 25 February 2017 Spring 2017 25 February 2017 Directions: In groups of 4-5, work on the following exercises. Do not proceed to the next exercise until everyone in your group has the answer and understands why the answer

More information

ECE Fall st Midterm Examination (120 Minutes, closed book)

ECE Fall st Midterm Examination (120 Minutes, closed book) ECE Fall 2009 1 st Midterm Examination (120 Minutes, closed book) Name: Question Score Student ID: 1 (15) 2 (20) 3 (20) 4 (15) 5 (20) 6 (10) NOTE: Any questions on writing code must be answered in Java

More information

infix expressions (review)

infix 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 information

Queue ADT. January 31, 2018 Cinda Heeren / Geoffrey Tien 1

Queue ADT. January 31, 2018 Cinda Heeren / Geoffrey Tien 1 Queue ADT Cinda Heeren / Geoffrey Tien 1 PA1 testing Your code must compile with our private test file Any non-compiling submissions will receive zero Note that only functions that are called will be compiled

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard 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 information

List ADT. B/W Confirming Pages

List ADT. B/W Confirming Pages wu3399_ch8.qxd //7 :37 Page 98 8 List ADT O b j e c t i v e s After you have read and studied this chapter, you should be able to Describe the key features of the List ADT. the List ADT using an array

More information

1 P age DS & OOPS / UNIT II

1 P age DS & OOPS / UNIT II UNIT II Stacks: Definition operations - applications of stack. Queues: Definition - operations Priority queues - De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) An interesting definition for stack element The stack element could be of any data type struct stackelement int etype; union int ival;

More information

CS/CE 2336 Computer Science II

CS/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 information

Dynamic Data Structures

Dynamic Data Structures Dynamic Data Structures We have seen that the STL containers vector, deque, list, set and map can grow and shrink dynamically. We now examine how some of these containers can be implemented in C++. To

More information

COMP 250 Winter generic types, doubly linked lists Jan. 28, 2016

COMP 250 Winter generic types, doubly linked lists Jan. 28, 2016 COMP 250 Winter 2016 5 generic types, doubly linked lists Jan. 28, 2016 Java generics In our discussion of linked lists, we concentrated on how to add or remove a node from the front or back of a list.

More information

4.1 Ordered Lists Revisited

4.1 Ordered Lists Revisited Chapter 4 Linked-lists 4.1 Ordered Lists Revisited Let us revisit our ordered-list. Let us assume that we use it for storing roll numbers of students in a class in ascending order. We can make the assumption

More information

Amortized Analysis. 0.1 Amortized Case Analysis. CITS2200 Data Structures and Algorithms

Amortized Analysis. 0.1 Amortized Case Analysis. CITS2200 Data Structures and Algorithms 0.1 Amortized Case Analysis CITS2200 Data Structures and Algorithms Topic 8 Amortized Analysis Amortized Case Analysis for Data Structures An example of amortized analysis using Multipop stack The Simplist

More information

Unit 4: Stacks and Queues

Unit 4: Stacks and Queues Unit 4: Stacks and Queues Engineering 4892: Data Structures Faculty of Engineering & Applied Science Memorial University of Newfoundland June 1, 2011 ENGI 4892 (MUN) Unit 4 June 1, 2011 1 / 24 1 Stacks

More information

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage: Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let

More information

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location

More information

Data Structures and Algorithms Notes

Data 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 information

THE UNIVERSITY OF WESTERN AUSTRALIA

THE UNIVERSITY OF WESTERN AUSTRALIA THE UNIVERSITY OF WESTERN AUSTRALIA MID SEMESTER EXAMINATION April 2016 SCHOOL OF COMPUTER SCIENCE & SOFTWARE ENGINEERING DATA STRUCTURES AND ALGORITHMS CITS2200 This Paper Contains: 6 Pages 10 Questions

More information

Stacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle.

Stacks. 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 information

Cpt S 122 Data Structures. Data Structures

Cpt S 122 Data Structures. Data Structures Cpt S 122 Data Structures Data Structures Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Self Referential Structures Dynamic Memory Allocation

More information

CSE 373 Data Structures and Algorithms. Lecture 2: Queues

CSE 373 Data Structures and Algorithms. Lecture 2: Queues CSE 373 Data Structures and Algorithms Lecture 2: Queues Queue ADT queue: A list with the restriction that insertions are done at one end and deletions are done at the other First-In, First-Out ("FIFO

More information

1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University

1/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 information

Stacks Fall 2018 Margaret Reid-Miller

Stacks 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 information

CSIS 10B Lab 2 Bags and Stacks

CSIS 10B Lab 2 Bags and Stacks CSIS 10B Lab 2 Bags and Stacks Part A Bags and Inheritance In this part of the lab we will be exploring the use of the Bag ADT to manage quantities of data of a certain generic type (listed as T in the

More information

CSE 143 SAMPLE MIDTERM

CSE 143 SAMPLE MIDTERM CSE 143 SAMPLE MIDTERM 1. (5 points) In some methods, you wrote code to check if a certain precondition was held. If the precondition did not hold, then you threw an exception. This leads to robust code

More information

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

Stack 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

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

Data structure is an organization of information, usually in memory, for better algorithm efficiency.

Data structure is an organization of information, usually in memory, for better algorithm efficiency. Lecture 01 Introduction Wednesday, 29 July 2015 12:59 pm Data structure is an organization of information, usually in memory, for better algorithm efficiency. Abstract data types (ADTs) are a model for

More information

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.

Wentworth 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 information

COMP 250 Midterm #2 March 11 th 2013

COMP 250 Midterm #2 March 11 th 2013 NAME: STUDENT ID: COMP 250 Midterm #2 March 11 th 2013 - This exam has 6 pages - This is an open book and open notes exam. No electronic equipment is allowed. 1) Questions with short answers (28 points;

More information

III Data Structures. Dynamic sets

III Data Structures. Dynamic sets III Data Structures Elementary Data Structures Hash Tables Binary Search Trees Red-Black Trees Dynamic sets Sets are fundamental to computer science Algorithms may require several different types of operations

More information

CS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes

CS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes CS/ENGRD 2110 SPRING 2019 Lecture 7: Interfaces and Abstract Classes http://courses.cs.cornell.edu/cs2110 1 Announcements 2 A2 is due Thursday night (14 February) Go back to Lecture 6 & discuss method

More information

LECTURE OBJECTIVES 6-2

LECTURE OBJECTIVES 6-2 The Queue ADT LECTURE OBJECTIVES Examine queue processing Define a queue abstract data type Demonstrate how a queue can be used to solve problems Examine various queue implementations Compare queue implementations

More information

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12 CS 151 Linked Lists, Recursively Implemented 1 2 Linked Lists, Revisited Recall that a linked list is a structure that represents a sequence of elements that are stored non-contiguously in memory. We can

More information

Abstract Data Types. Abstract Data Types

Abstract Data Types. Abstract Data Types Abstract Data Types Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria Wolfgang.Schreiner@risc.jku.at http://www.risc.jku.at Wolfgang Schreiner

More information

Lecture 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 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 information

CS 61B Spring 2017 Guerrilla Section 3 Solutions

CS 61B Spring 2017 Guerrilla Section 3 Solutions Spring 2017 25 February 2017 Directions: In groups of 4-5, work on the following exercises. Do not proceed to the next exercise until everyone in your group has the answer and understands why the answer

More information

Stacks. Common data structures - useful for organizing data for specific tasks Lists Stacks - an Abstract Data Type

Stacks. Common data structures - useful for organizing data for specific tasks Lists Stacks - an Abstract Data Type Stacks Common data structures - useful for organizing data for specific tasks Lists Stacks - an Abstract Data Type Class interface Polymorphism Use of List as representation of Stacks Pop versus Peek 1

More information

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.

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. 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 information

Example Final Questions Instructions

Example Final Questions Instructions Example Final Questions Instructions This exam paper contains a set of sample final exam questions. It is for practice purposes only. You ll most likely need longer than three hours to answer all the questions.

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

Queues. Data Structures and Design with Java and JUnit Rick Mercer 18-1

Queues. Data Structures and Design with Java and JUnit Rick Mercer 18-1 Queues Data Structures and Design with Java and JUnit Rick Mercer 18-1 A Queue ADT First in first out access A Queue is another name for waiting line Example: Submit jobs to a network printer What gets

More information

Stack and Its Implementation

Stack and Its Implementation Stack and Its Implementation Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - 3131 1 Definition of Stack Usage of Stack Outline

More information

More Data Structures (Part 1) Stacks

More Data Structures (Part 1) Stacks More Data Structures (Part 1) Stacks 1 Stack examples of stacks 2 Top of Stack top of the stack 3 Stack Operations classically, stacks only support two operations 1. push 2. pop add to the top of the stack

More information

Linked List Implementation of Queues

Linked List Implementation of Queues Outline queue implementation: linked queue application of queues and stacks: data structure traversal double-ended queues application of queues: simulation of an airline counter random numbers recursion

More information

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) 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 information

Arrays. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Arrays. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html 1 Arrays Arrays in Java an array is a container object that holds a fixed number of values of a single type the length of an array is established when the array is created 2 https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

More information

Basic Data Structures

Basic 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 information

Lecture 3: Queues, Testing, and Working with Code

Lecture 3: Queues, Testing, and Working with Code Lecture 3: Queues, Testing, and Working with Code Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1 Clearing up Stacks CSE 373 SU 18 BEN JONES 2 Clearing up Stacks CSE 373 SU 18 BEN JONES 3 Clearing

More information

Lecture 2: Stacks and Queues

Lecture 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 information

Stacks have many uses Arithmetic Language parsing Keeping track of recursion (more in this in a week or so)

Stacks have many uses Arithmetic Language parsing Keeping track of recursion (more in this in a week or so) Implementing Stacks Basics of Exceptions OK, so stacks are useful Stacks have many uses Arithmetic Language parsing Keeping track of recursion (more in this in a week or so) How can stacks be implemented?

More information

Collections Chapter 12. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Collections Chapter 12. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Collections Chapter 12 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Scope Introduction to Collections: Collection terminology The Java Collections API Abstract nature of collections

More information