CompSci 100 Prog Design and Analysis II Sept 14, 2010 Prof. Rodger CompSci 100, Fall 20101.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 The Collections API.
Advertisements

Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
ITEC200 Week04 Lists and the Collection Interface.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
The List ADT Textbook Sections
Polymorphism. 3 Fundamental Properties of OO 1. Encapsulation 2. Polymorphism 3. Inheritance These are the 3 building blocks of object-oriented design.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Computer Science 209 Software Development Equality and Comparisons.
COMP 121 Week 11: Linked Lists. Objectives Understand how single-, double-, and circular-linked list data structures are implemented Understand the LinkedList.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Using ArrayList. Lecture Objectives To understand the foundations behind the ArrayList class Explore some of the methods of the ArrayList class.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
Chapter 4 Linked Structures. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 4-2 Chapter Objectives Describe the use of references to create.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 10: ArrayList.
Chapter 10 2D Arrays Collection Classes. Topics Arrays with more than one dimension Java Collections API ArrayList Map.
ArrayLists.  The Java API includes a class named ArrayList. The introduction to the ArrayList class in the Java API documentation is shown below.  java.lang.Object.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
Linked Lists. RHS – SOC 2 Linked lists We can already store collec- tions of objects in arrays and array lists – why would we need other data structures…?
CPS 100, Spring Analysis: Algorithms and Data Structures l We need a vocabulary to discuss performance and to reason about alternative algorithms.
Lists Based on content from: Java Foundations, 3rd Edition.
Arrays and Linked Lists "All the kids who did great in high school writing pong games in BASIC for their Apple II would get to college, take CompSci 101,
Sadegh Aliakbary Sharif University of Technology Fall 2010.
The Java Collections Framework (JCF) Introduction and review 1.
CSE 143 Lecture 2 More ArrayList ; classes and objects reading: 10.1; slides created by Marty Stepp and Hélène Martin
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Chapter 18 Java Collections Framework
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
CS 307 Fundamentals of Computer ScienceLinked Lists 1 Topic 14 Linked Lists "All the kids who did great in high school writing pong games in BASIC for.
CompSci 100e Program Design and Analysis II March 15, 2011 Prof. Rodger CompSci 100e, Spring20111.
CS-2851 Dr. Mark L. Hornick 1 Generic Java Classes Implementing your own generic classes.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
(c) University of Washington16-1 CSC 143 Java Lists via Links Reading: Ch. 23.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
COMP 121 Week 11: Linked Lists.
M180: Data Structures & Algorithms in Java Algorithm Analysis Arab Open University 1.
CompSci 100e 3.1 Plan for the week l Classes and Objects l Model-View-Controller l Maps and Hashing l Upcoming  Towards Algorithm analysis l APTs:  IsomorphicWords,
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 8 Lists, Iterators, and Doubly Linked Lists.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Computer Science 209 Software Development Inheritance and Composition.
Compsci 100, Fall Analysis: Algorithms and Data Structures l We need a vocabulary to discuss performance  Reason about alternative algorithms.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
Collections and Iteration Week 13.  Collections  ArrayList objects  Using loops with collections Collections and Iteration CONCEPTS COVERED THIS WEEK.
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
CS Fall 2012, Lab 04 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /29/2016 Changes of Office Hours  Monday.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
CS-2851 Dr. Mark L. Hornick 1 Linked-List collections Structure and Implementation.
3/21/2016IT 2751 Tow kinds of Lists Array What can be done? What can be easily done? student 1 student 2 student 3 student 4 Linked List student 2 student.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
CompSci 100e Program Design and Analysis II January 27, 2011 Prof. Rodger CompSci 100e, Spring20111.
TAFTD (Take Aways for the Day)
Building Java Programs
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Plan for the Week Review Big-Oh
Owen Astrachan Jeff Forbes October 19, 2017
Tools: Solve Computational Problems
TAFTW (Take Aways for the Week)
Lecture 2: Implementing ArrayIntList reading:
Building Java Programs
Building Java Programs
Building Java Programs
Lecture 2: Implementing ArrayIntList reading:
Welcome to CSE 143! Go to pollev.com/cse143.
Building Java Programs
Lecture 7: Linked List Basics reading: 16.2
CMPE212 – Reminders Assignment 4 on Inheritance due next Friday.
Presentation transcript:

CompSci 100 Prog Design and Analysis II Sept 14, 2010 Prof. Rodger CompSci 100, Fall 20101

Announcements APT-ONE due today Markov and APT-TWO out today Recitation this week focuses on Markov. You should start it before then CompSci 100, Fall 20102

What is the plan for the day How are objects compared in Java? – When would you want to compare? – What can’t be compared? Empirical and Analytical Analysis – Why are some lists different? – Why is adding in the middle fast? – Why is adding in the middle slow? 3CompSci 100, Fall 2010

From Comparable to Comparator When a class implements Comparable then … – Instances are comparable to each other “apple” 2 Sorting Strings, Sorting WordPairs, … Method compareTo invoked when … – Comparable types the parameter to compareTo – Return 0 according to results of comparison Suppose we want to change how Strings compare – Or change class Foo implements Comparable – What if we need more than one way to compare Foo’s? 4CompSci 100, Fall 2010

java.util.Comparator How does sorting work in general and in Java? – Characteristics of Java library sort methods – What can be sorted? – How do you change how sorting works? APT ClientsList: example to explore Comparator – Creating new Comparator: nested class Should it be public? Private? Matter? – Comparator could anonymous, but then issues. What does it mean to implement Comparable? – Other Java interfaces: cloneable, serializable, … 5CompSci 100, Fall 2010

What is a list in Java? Collection of elements, operations? – Add, remove, traverse, … – What can a list do to itself? – What can we do to a list? Why more than one kind of list: Array and Linked? – Useful in different applications – How do we analyze differences? 6CompSci 100, Fall 2010

Analyze Data Structures public double removeFirst(List list) { double start = System.currentTimeMillis(); while (list.size() != 1){ list.remove(0); } double end = System.currentTimeMillis(); return (end-start)/1000.0; } List linked = new LinkedList (); List array = new ArrayList (); double ltime = splicer.removeFirst(splicer.create(linked,100000)); double atime = splicer.removeFirst(splicer.create(array,100000)); Time taken to remove the first element? 7CompSci 100, Fall 2010

Removing first element sizelinkarray CompSci 100, Fall 2010

Middle Index Removal public double removeMiddleIndex(List list) { double start = System.currentTimeMillis(); while (list.size() != 1){ list.remove(list.size()/2); } double end = System.currentTimeMillis(); return (end-start)/1000.0; } What operations could be expensive here? – Explicit: size, remove – Implicit: find n th element 9CompSci 100, Fall 2010

Remove middle element sizelinkarray CompSci 100, Fall 2010