Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University

Size: px
Start display at page:

Download "Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University"

Transcription

1 Lecture 6 COMP1006/1406 (the OOP course) Summer 2014 M. Jason Hinek Carleton University

2 today s agenda assignments A1,A2,A3 are all marked A4 marking just started A5 is due Friday, A6 is due Monday a quick look back abstract things final things generics, interfaces, Comparable OOP and Java interfaces polymorphism inheritance 2

3 announcements Midterm 6:05-7:35pm, Wednesday July 30 UC 231 no aids class will resume at 8:00pm in the usual room All requests for accommodations must be received by noon on Friday, July 25 3

4 announcements Tutorials 6-8pm tutorial (no help for assignments) 8-9pm general help from TAs (including assignments) go to both if it will help if there is a seat you are welcome to attend (no homework help during first two hours) Office Hours Tuesday 4:00-6:00 in HP4155 (Sean) Thursday 11:00-12:30 in HP532 (Jason) for class material or Friday s assignment Thursday 5:00-6:00 in HP4155 (Connor) Friday 11:00-12:30 in HP5332 (Jason) for class material or Monday s assignment 4

5 last time... abstract classes cannot be instantiated no objects of the class can exist are valid reference types can have variables of this type (cannot use new and create an object of an abstract class) no restrictions on what can be in an abstract class attributes, methods, constructors does not need to have abstract methods cannot be final intention is for a descendant class to be concrete a concrete class can be instantiated (can use new and create an object of a concrete class) 5

6 last time... abstract methods have no body (definition) public abstract String getname(); forces class to also be abstract cannot be final intention is for a descendant class to define this method 6

7 last time... final final classes cannot be extended and cannot also be abstract final methods cannot be overriden and cannot also be abstract final attributes cannot change they must be defined (using initialization block or in constructor) the reference they store cannot be changed once defined 7

8 abstract classes why use abstract classes? abstract GameCharacters User abstract Game Friend Foe provides interface between implementation and users of code helps modularize code 8

9 let s take a break... for 5 minutes 9

10 interfaces Java interfaces contain method declarations (without definition) are public by default (you can omit this) implicitly abstract (you do not write this) contain constant attributes are public static final by default (can omit this) can extend any number of other interfaces are valid reference type but cannot be instantiated (like an abstract class) 10

11 interfaces public interface Flyable{ } int C = ; boolean takeoff(); boolean fly(); boolean land(); provides a contract between code and users of code specifies behaviour does not specify state any class can implement this interface 11

12 abstract class vs interface abstract class valid reference data type not instantiable static and instance attributes method declarations and definitions defines identity of children (is-a) class extends 0,1 abstract class all subclasses are (very) related Java interface valid reference data type not instantiable public static final constants method declarations only can define identity (is-a) often defines abilities (-able) class implements n 0 interfaces independent classes implement same interface 12

13 abstract class vs interface abstract class valid reference data type not instantiable static and instance attributes method declarations and definitions defines identity of children (is-a) class extends 0,1 abstract class all subclasses are (very) related Java interface valid reference data type not instantiable public static final constants method declarations only can define identity (is-a) often defines abilities (-able) class implements n 0 interfaces independent classes implement same interface 12

14 data types 13

15 data types 13

16 generics allow us to create classes that uses any data type (non-primitive) public class Box<E>{ public E data; } public Box(E object){ this.data = object; } public class Box{ public Object data; } public Box(Object object){ this.data = object; } we could already do this by storing Objects this involves a lot of overhead checking types casting 14

17 generics allow us to create methods that use/input/return any data type (non-primitive) public static <T,K> T foo(int x, K[] k){ if( k.length > x ){ return new T(x); }else{ return new T(k[0].toString()); } } how could we do this with generics? 15

18 generics allow us to create methods that use/input/return any data type (non-primitive) public static <T,K> T foo(int x, K[] k){ if( k.length > x ){ return new T(x); }else{ return new T(k[0].toString()); } } how could we do this with generics? Java 8... (pass methods as input arguments) 15

19 generics generics can be a very useful tool in Java (and other languages) allows for generic algorithms eliminates casts provides stronger compile time type checks only work with Objects! (no primitive data types) 16

20 let s take a break... for 5 minutes 17

21 this again... this has two uses a reference to the current object used in instance methods cannot be used in static methods 18

22 this again... this has two uses a reference to the current object used in instance methods cannot be used in static methods used to call a constructor from within a constructor 18

23 this again... this has two uses a reference to the current object used in instance methods cannot be used in static methods used to call a constructor from within a constructor public Box(String name, int id){ // constructor this.name = name; this.id = id; } public Box(){ this("no name", -1); } public Box me(){ return this; } // constructor // method 18

24 initialization there are several ways to do initialization constructors (for objects) initialization blocks code gets added to constructors static initialization blocks 19

25 initialization there are several ways to do initialization constructors (for objects) initialization blocks code gets added to constructors static initialization blocks public class Box{ static String s1; String s2; static { System.out.println("static initialization block") } { } System.out.println("static initialization block") s2 = s1 + s1;... 19

26 inheritance access modifiers public class access, package access, subclass access, world access protected class access, package access, subclass access none (friendly) class access, package access private class access 20

27 inheritance access modifiers public class access, package access, subclass access, world access protected class access, package access, subclass access none (friendly) class access, package access private class access which modifier should you use? 20

28 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. 21

29 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. you will have noticed that this is also true for arrays sometimes too... 21

30 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. you will have noticed that this is also true for arrays sometimes too... Java provides another for loop to make this easier 21

31 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. you will have noticed that this is also true for arrays sometimes too... Java provides another for loop to make this easier for(type t: c) 21

32 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. you will have noticed that this is also true for arrays sometimes too... Java provides another for loop to make this easier for(type t: c) for each Type t in c,... 21

33 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. you will have noticed that this is also true for arrays sometimes too... Java provides another for loop to make this easier for(type t: c) for each Type t in c,... for(string s: list) 21

34 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. you will have noticed that this is also true for arrays sometimes too... Java provides another for loop to make this easier for(type t: c) for each Type t in c,... for(string s: list) for each String s in list,... 21

35 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. you will have noticed that this is also true for arrays sometimes too... Java provides another for loop to make this easier for(type t: c) for each Type t in c,... for(string s: list) for each String s in list,... for(arraylist<string> list: biglist) 21

36 for-each loops from the Oracle Java pages... Iterating over a collection is uglier than it needs to be. you will have noticed that this is also true for arrays sometimes too... Java provides another for loop to make this easier for(type t: c) for each Type t in c,... for(string s: list) for each String s in list,... for(arraylist<string> list: biglist) for each ArrayList<String> list in biglist,... 21

37 abstract data types an abstract data type or ADT is a collection of data a set of operations on that data possibly specified runtimes for the operation 22

38 let s take a break... for 5 minutes 23

39 some fundamental ADTs stack 24

40 some fundamental ADTs stack ordered collection of data (top is the last item added ) 24

41 some fundamental ADTs stack ordered collection of data (top is the last item added ) push (add an element to the top) pop (remove top element) peek (look at the top) isempty (is the stack empty) 24

42 some fundamental ADTs stack ordered collection of data (top is the last item added ) push (add an element to the top) pop (remove top element) Last In First Out (LIFO) peek (look at the top) isempty (is the stack empty) 24

43 some fundamental ADTs queue 25

44 some fundamental ADTs queue ordered collection of data (front and back) 25

45 some fundamental ADTs queue ordered collection of data (front and back) enqueue (add an element to the back) dequeue (remove element from the front) peek (look at the front) isempty (is the queue empty) 25

46 some fundamental ADTs queue ordered collection of data (front and back) enqueue (add an element to the back) dequeue (remove element from the front) First In First Out (FIFO) peek (look at the front) isempty (is the queue empty) 25

47 some fundamental ADTs stack and queue both are restricted lists stack removes items according to LIFO queue removes items according to FIFO 26

48 some fundamental ADTs stack and queue both are restricted lists stack removes items according to LIFO queue removes items according to FIFO Why do we need (or want) restricted lists? 26

49 some fundamental ADTs stack and queue both are restricted lists stack removes items according to LIFO queue removes items according to FIFO Why do we need (or want) restricted lists? forces the LIFO or FIFO principal might be more efficient 26

50 some fundamental ADTs stack and queue both are restricted lists stack removes items according to LIFO queue removes items according to FIFO Why do we need (or want) restricted lists? forces the LIFO or FIFO principal prevents intended misuse (cheating) prevents unintended misuse (mistakes) might be more efficient 26

51 some fundamental ADTs stack and queue both are restricted lists stack removes items according to LIFO queue removes items according to FIFO Why do we need (or want) restricted lists? forces the LIFO or FIFO principal prevents intended misuse (cheating) prevents unintended misuse (mistakes) might be more efficient array vs linked lists (we ll look at this soon) 26

52 some fundamental ADTs priority queue a queue in which removal is based on a priority (regardless of when added) highest priority item removed first emergency room in a hospital uses a priority queue deque a double-ended queue allows arbitrary adding/removing from front and back set an unordered collection of data add, remove, check for membership, size, etc 27

53 some fundamental ADTs map (or dictionary) 28

54 some fundamental ADTs map (or dictionary) a collection of (key,value) pairs keys are unique 28

55 some fundamental ADTs map (or dictionary) a collection of (key,value) pairs keys are unique mutable keys are dangerous some maps have order and some do not 28

Day 6. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 6. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 6 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments Assignment 3 is due on Monday a quick look back abstract classes and interfaces casting objects abstract data

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

Lecture 2: Implementing ADTs

Lecture 2: Implementing ADTs Lecture 2: Implementing ADTs Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Discuss with your neighbors! From last lecture: - What is an ADT? - What is a data structure? From CSE

More information

Day 5. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 5. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 5 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments Assignment 2 is in Assignment 3 is out a quick look back inheritance and polymorphism interfaces the Comparable

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

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

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August Polymorphism, Dynamic Binding and Interface 2 4 pm Thursday 7/31/2008 @JD2211 1 Announcement Next week is off The class will continue on Tuesday, 12 th August 2 Agenda Review Inheritance Abstract Array

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

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

Data Structures. BSc in Computer Science University of New York, Tirana. Assoc. Prof. Marenglen Biba 1-1

Data Structures. BSc in Computer Science University of New York, Tirana. Assoc. Prof. Marenglen Biba 1-1 Data Structures BSc in Computer Science University of New York, Tirana Assoc. Prof. Marenglen Biba 1-1 General info Course : Data Structures (3 credit hours) Instructor : Assoc. Prof. Marenglen Biba Office

More information

Lecture 4. The Java Collections Framework

Lecture 4. The Java Collections Framework Lecture 4. The Java s Framework - 1 - Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework - 2 - Learning Outcomes From this lecture you should

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

CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh University of Toronto Scarborough

CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh University of Toronto Scarborough CSCA48 Summer 2018 Week 3: Priority Queue, Linked Lists Marzieh Ahmadzadeh University of Toronto Scarborough Administrative Detail All practicals are up on course website. Term test # 1 and #2 schedule

More information

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

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

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

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Lauren Milne Summer 2015 CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Lauren Milne Summer 2015 Welcome! We will learn fundamental data structures and algorithms for organizing and processing

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

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

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

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

CSE 332: Data Structures. Spring 2016 Richard Anderson Lecture 1 CSE 332: Data Structures Spring 2016 Richard Anderson Lecture 1 CSE 332 Team Instructors: Richard Anderson anderson at cs TAs: Hunter Zahn, Andrew Li hzahn93 at cs lia4 at cs 2 Today s Outline Introductions

More information

The Java Collections Framework. Chapters 7.5

The Java Collections Framework. Chapters 7.5 The Java s Framework Chapters 7.5 Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework Outline Introduction to the Java s Framework Iterators Interfaces,

More information

Announcements. CS18000: Problem Solving And Object-Oriented Programming

Announcements. CS18000: Problem Solving And Object-Oriented Programming Announcements Exam 1 Monday, February 28 Wetherill 200, 4:30pm-5:20pm Coverage: Through Week 6 Project 2 is a good study mechanism Final Exam Tuesday, May 3, 3:20pm-5:20pm, PHYS 112 If you have three or

More information

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

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

3137 Data Structures and Algorithms in C++

3137 Data Structures and Algorithms in C++ 3137 Data Structures and Algorithms in C++ Lecture 3 July 12 2006 Shlomo Hershkop 1 Announcements Homework 2 out tonight Please make sure you complete hw1 asap if you have issues, please contact me will

More information

CS24 Week 4 Lecture 2

CS24 Week 4 Lecture 2 CS24 Week 4 Lecture 2 Kyle Dewey Overview Linked Lists Stacks Queues Linked Lists Linked Lists Idea: have each chunk (called a node) keep track of both a list element and another chunk Need to keep track

More information

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

CSE 326 Team. Today s Outline. Course Information. Instructor: Steve Seitz. Winter Lecture 1. Introductions. Web page: CSE 326 Team CSE 326: Data Structures Instructor: Steve Seitz TAs: Winter 2009 Steve Seitz Lecture 1 Eric McCambridge Brent Sandona Soyoung Shin Josh Barr 2 Today s Outline Introductions Administrative

More information

CT 229 Object-Oriented Programming Continued

CT 229 Object-Oriented Programming Continued CT 229 Object-Oriented Programming Continued 24/11/2006 CT229 Summary - Inheritance Inheritance is the ability of a class to use the attributes and methods of another class while adding its own functionality

More information

COMPUTER SCIENCE IN THE NEWS (TWO YEARS AGO) CS61A Lecture 16 Mutable Data Structures TODAY REVIEW: OOP CLASS DESIGN 7/24/2012

COMPUTER SCIENCE IN THE NEWS (TWO YEARS AGO) CS61A Lecture 16 Mutable Data Structures TODAY REVIEW: OOP CLASS DESIGN 7/24/2012 COMPUTER SCIENCE IN THE NEWS (TWO YEARS AGO) CS61A Lecture 16 Mutable Data Structures Jom Magrotker UC Berkeley EECS July 16, 2012 http://articles.nydailynews.com/2010 04 27/news/27062899_1_marks death

More information

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques 1 CPSC2620 Advanced Programming Spring 2003 Instructor: Dr. Shahadat Hossain 2 Today s Agenda Administrative Matters Course Information Introduction to Programming Techniques 3 Course Assessment Lectures:

More information

== isn t always equal?

== isn t always equal? == isn t always equal? In Java, == does the expected for primitives. int a = 26; int b = 26; // a == b is true int a = 13; int b = 26; // a == b is false Comparing two references checks if they are pointing

More information

CS 206 Introduction to Computer Science II

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

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques () Lecture 20 February 28, 2018 Transition to Java Announcements HW05: GUI programming Due: THURSDAY!! at 11:59:59pm Lots of TA office hours today Thursday See Piazza

More information

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 Data Structures Course Review FINAL Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Final When: Wednesday (12/12) 1:00 pm -3:00 pm Where: In Class

More information

CSCI 136 Data Structures & Advanced Programming. Lecture 13 Fall 2018 Instructors: Bill 2

CSCI 136 Data Structures & Advanced Programming. Lecture 13 Fall 2018 Instructors: Bill 2 CSCI 136 Data Structures & Advanced Programming Lecture 13 Fall 2018 Instructors: Bill 2 Announcements Lab today! After mid-term we ll have some non-partner labs It s Lab5 not Lab 4 Mid-term exam is Wednesday,

More information

Today s lecture. CS 314 fall 01 C++ 1, page 1

Today s lecture. CS 314 fall 01 C++ 1, page 1 Today s lecture Midterm Thursday, October 25, 6:10-7:30pm general information, conflicts Object oriented programming Abstract data types (ADT) Object oriented design C++ classes CS 314 fall 01 C++ 1, page

More information

cs Java: lecture #6

cs Java: lecture #6 cs3101-003 Java: lecture #6 news: homework #5 due today little quiz today it s the last class! please return any textbooks you borrowed from me today s topics: interfaces recursion data structures threads

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

CSC148H Week 3. Sadia Sharmin. May 24, /20

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

CS 302 ALGORITHMS AND DATA STRUCTURES

CS 302 ALGORITHMS AND DATA STRUCTURES CS 302 ALGORITHMS AND DATA STRUCTURES A famous quote: Program = Algorithm + Data Structure General Problem You have some data to be manipulated by an algorithm E.g., list of students in a school Each student

More information

Day 2. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 2. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 2 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda a quick look back (Monday s class) assignments a1 is due on Monday a2 will be available on Monday and is due the following

More information

CS61A Lecture 20 Object Oriented Programming: Implementation. Jom Magrotker UC Berkeley EECS July 23, 2012

CS61A Lecture 20 Object Oriented Programming: Implementation. Jom Magrotker UC Berkeley EECS July 23, 2012 CS61A Lecture 20 Object Oriented Programming: Implementation Jom Magrotker UC Berkeley EECS July 23, 2012 COMPUTER SCIENCE IN THE NEWS http://www.theengineer.co.uk/sectors/electronics/news/researchers

More information

Announcements/Follow-ups

Announcements/Follow-ups Announcements/Follow-ups Midterm 2 graded Average was 52/80 (63%), Std. Dev. was 12 P5 and Lab8 P5 due tomorrow Very light Lab8 Practice with collections Due at end of lab period P6 posted tomorrow Due

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

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

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2. Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.

More information

CMSC 341 Priority Queues & Heaps. Based on slides from previous iterations of this course

CMSC 341 Priority Queues & Heaps. Based on slides from previous iterations of this course CMSC 341 Priority Queues & Heaps Based on slides from previous iterations of this course Today s Topics Priority Queues Abstract Data Type Implementations of Priority Queues: Lists BSTs Heaps Heaps Properties

More information

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade Final Exam Review Final Exam Mon, May 5, 2:00PM to 4:30PM CS 2308 Spring 2014 Jill Seaman Closed book, closed notes, clean desk Comprehensive (covers entire course) 30% of your final grade I recommend

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

CS61A Lecture 16 Mutable Data Structures. Jom Magrotker UC Berkeley EECS July 16, 2012

CS61A Lecture 16 Mutable Data Structures. Jom Magrotker UC Berkeley EECS July 16, 2012 CS61A Lecture 16 Mutable Data Structures Jom Magrotker UC Berkeley EECS July 16, 2012 COMPUTER SCIENCE IN THE NEWS (TWO YEARS AGO) http://articles.nydailynews.com/2010 04 27/news/27062899_1_marks death

More information

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004 Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...

More information

CSE 373 SEPTEMBER 29 STACKS AND QUEUES

CSE 373 SEPTEMBER 29 STACKS AND QUEUES CSE 373 SEPTEMBER 29 STACKS AND QUEUES DESIGN DECISIONS Shopping list? DESIGN DECISIONS Shopping list? What sorts of behavior do shoppers exhibit? What constraints are there on a shopper? What improvements

More information

CSE 373: Data Structures and Algorithms

CSE 373: Data Structures and Algorithms CSE 373: Data Structures and Algorithms Lecture 2: Wrap up Queues, Asymptotic Analysis, Proof by Induction Instructor: Lilian de Greef Quarter: Summer 2017 Today: Announcements Wrap up Queues Begin Asymptotic

More information

CSC148 Week 2. Larry Zhang

CSC148 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 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

Announcements/Follow-ups

Announcements/Follow-ups Announcements/Follow-ups Midterm #2 Friday Everything up to and including today Review section tomorrow Study set # 6 online answers posted later today P5 due next Tuesday A good way to study Style omit

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

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

PRIORITY QUEUES AND HEAPS

PRIORITY QUEUES AND HEAPS PRIORITY QUEUES AND HEAPS Lecture 17 CS2110 Spring 201 Readings and Homework 2 Read Chapter 2 A Heap Implementation to learn about heaps Exercise: Salespeople often make matrices that show all the great

More information

Stacks and Queues. Introduction to abstract data types (ADTs) Stack ADT. Queue ADT. Time permitting: additional Comparator example

Stacks and Queues. Introduction to abstract data types (ADTs) Stack ADT. Queue ADT. Time permitting: additional Comparator example Stacks and Queues Introduction to abstract data types (ADTs) Stack ADT applications interface for Java Stack ex use: reverse a sequence of values Queue ADT applications interface for Java Queue Time permitting:

More information

Basic Data Structures 1 / 24

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

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours: CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Thursday 12:00 PM 2:00 PM Friday 8:30 AM 10:30 AM OR request appointment via e-mail

More information

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object Oriented Programming. Java-Lecture 11 Polymorphism Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class

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

CSE 373: Introduction, ADTs, Design Decisions, Generics. Michael Lee Wednesday Jan 3, 2017

CSE 373: Introduction, ADTs, Design Decisions, Generics. Michael Lee Wednesday Jan 3, 2017 CSE 373: Introduction, ADTs, Design Decisions, Generics Michael Lee Wednesday Jan 3, 2017 1 Overview Michael Lee (mlee42@cs.washington.edu) Currently working on a master s degree in Computer Science Supervised

More information

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

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved Stacks Chapter 5 Copyright 2012 by Pearson Education, Inc. All rights reserved Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced

More information

COMP Data Structures

COMP Data Structures COMP 2140 - Data Structures Shahin Kamali Topic 3 - Algorithm Analysis University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 34 Abstract Data Types Definition An abstract

More information

Stacks and Queues. Gregory D. Weber. CSCI C243 Data Structures

Stacks and Queues. Gregory D. Weber. CSCI C243 Data Structures Stacks and Queues Gregory D. Weber CSCI C243 Data Structures Principal Points 1. The Stack interface: how to declare it, what it does. 2. Generics: why they were added to Java, how to use them. 3. The

More information

Chapter 14 Abstract Classes and Interfaces

Chapter 14 Abstract Classes and Interfaces Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden

More information

CS3500: Object-Oriented Design Fall 2013

CS3500: Object-Oriented Design Fall 2013 CS3500: Object-Oriented Design Fall 2013 Class 3 9.13.2013 Plan for Today Web-CAT Announcements Review terminology from last class Finish Recipe implementation of StackInt as a class Abstraction Barrier

More information

CS W3134: Data Structures in Java

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

More information

Abstract Classes and Interfaces

Abstract Classes and Interfaces Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass

More information

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University Lecture 2 COMP1406/1006 (the Java course) Fall 2013 M. Jason Hinek Carleton University today s agenda a quick look back (last Thursday) assignment 0 is posted and is due this Friday at 2pm Java compiling

More information

Name CPTR246 Spring '17 (100 total points) Exam 3

Name CPTR246 Spring '17 (100 total points) Exam 3 Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Data Types Marius Kloft Content of this Lecture Example Abstract Data Types Lists, Stacks, and Queues Realization in Java Marius Kloft: Alg&DS, Summer Semester 2016 2 Problem

More information

CISC 3130 Data Structures Fall 2018

CISC 3130 Data Structures Fall 2018 CISC 3130 Data Structures Fall 2018 Instructor: Ari Mermelstein Email address for questions: mermelstein AT sci DOT brooklyn DOT cuny DOT edu Email address for homework submissions: mermelstein DOT homework

More information

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object Review: Diagrams for Inheritance - String makemodel - int mileage + (String, int) Class #3: Inheritance & Polymorphism Software Design II (CS 220): M. Allen, 25 Jan. 18 + (String, int) + void

More information

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu Physics 2660: Fundamentals of Scientific Computing Lecture 3 Instructor: Prof. Chris Neu (chris.neu@virginia.edu) Announcements Weekly readings will be assigned and available through the class wiki home

More information

Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009

Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009 Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009 23 Odds and Ends In this lecture, I want to touch on a few topics that we did not have time to cover. 23.1 Factory Methods

More information

Logistics. Half of the people will be in Wu & Chen The other half in DRLB A1 Will post past midterms tonight (expect similar types of questions)

Logistics. Half of the people will be in Wu & Chen The other half in DRLB A1 Will post past midterms tonight (expect similar types of questions) Data Structures Logistics Midterm next Monday Half of the people will be in Wu & Chen The other half in DRLB A1 Will post past midterms tonight (expect similar types of questions) Review on Wednesday Come

More information

Adam Blank Lecture 1 Winter 2017 CSE 332. Data Abstractions

Adam Blank Lecture 1 Winter 2017 CSE 332. Data Abstractions Adam Blank Lecture 1 Winter 2017 CSE 332 Data Abstractions CSE 332: Data Abstractions Welcome to CSE 332! Outline 1 Administrivia 2 A Data Structures Problem 3 Review of Stacks & Queues What Am I Getting

More information

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Interfaces vs. Inheritance Abstract Classes Inner Classes Readings This Week: No new readings. Consolidate! (Reminder: Readings

More information

CPSC 221: Algorithms and Data Structures Lecture #0: Introduction. Come up and say hello! Fibonacci. Fibonacci. Fibonacci. Fibonacci. (Welcome!

CPSC 221: Algorithms and Data Structures Lecture #0: Introduction. Come up and say hello! Fibonacci. Fibonacci. Fibonacci. Fibonacci. (Welcome! Come up and say hello! (Welcome!) CPSC 221: Algorithms and Data Structures Lecture #0: Introduction Kendra Cooper 2014W1 1 2 Fibonacci 0 + = Fibonacci 0 + = 1, 1, 2, 3, 5, 8, 13, 21, Definition: Applications,

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

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

CS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Interface Abstract data types Version of January 26, 2013 Abstract These lecture notes are meant

More information

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

Queues. Stacks and Queues

Queues. Stacks and Queues Queues Reading: RS Chapter 14 Slides are modified from those provided by Marty Stepp www.buildingjavaprograms.com 1 Stacks and Queues Sometimes a less powerful, but highly optimized collection is useful.

More information

ECE Object-Oriented Programming using C++ and Java

ECE Object-Oriented Programming using C++ and Java 1 ECE 30862 - Object-Oriented Programming using C++ and Java Instructor Information Name: Sam Midkiff Website: https://engineering.purdue.edu/~smidkiff Office: EE 310 Office hours: Tuesday, 2:30 to 4:00

More information

CS/ENGRD 2110 SPRING 2018

CS/ENGRD 2110 SPRING 2018 CS/ENGRD 2110 SPRING 2018 Lecture 7: Interfaces and http://courses.cs.cornell.edu/cs2110 1 2 St Valentine s Day! It's Valentines Day, and so fine! Good wishes to you I consign.* But since you're my students,

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http://www.cse.buffalo.edu/faculty/alphonce/sp17/cse443/index.php https://piazza.com/class/iybn4ndqa1s3ei Phases of a compiler Target

More information

Inheritance and Substitution (Budd chapter 8, 10)

Inheritance and Substitution (Budd chapter 8, 10) Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various

More information

EINDHOVEN UNIVERSITY OF TECHNOLOGY

EINDHOVEN UNIVERSITY OF TECHNOLOGY EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics & Computer Science Exam Programming Methods, 2IP15, Wednesday 17 April 2013, 09:00 12:00 TU/e THIS IS THE EXAMINER S COPY WITH (POSSIBLY INCOMPLETE)

More information

Abstract vs concrete data structures HEAPS AND PRIORITY QUEUES. Abstract vs concrete data structures. Concrete Data Types. Concrete data structures

Abstract vs concrete data structures HEAPS AND PRIORITY QUEUES. Abstract vs concrete data structures. Concrete Data Types. Concrete data structures 10/1/17 Abstract vs concrete data structures 2 Abstract data structures are interfaces they specify only interface (method names and specs) not implementation (method bodies, fields, ) HEAPS AND PRIORITY

More information

A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list.

A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list. A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list. the first element of the list a new element to (the Top of)

More information