CPS 100, Spring 2009 1.1 COMPSCI 100, Spring 2009 Owen Astrachan

Slides:



Advertisements
Similar presentations
CS /29/2004 (Recitation Objectives) and Computer Science and Objects and Algorithms.
Advertisements

Searching. 2 Searching an array of integers If an array is not sorted, there is no better algorithm than linear search for finding an element in it static.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Computer Science - I Course Introduction Computer Science Department Boston College Hao Jiang.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
Describing algorithms in pseudo code To describe algorithms we need a language which is: – less formal than programming languages (implementation details.
Abstract Data Types (ADTs) Data Structures The Java Collections API
Compsci 101, Spring COMPSCI 101, Spring 2012 Introduction to Computer Science Owen Astrachan
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
CPS 100, Fall COMPSCI 100, Fall 2011 Owen Astrachan w/ Michael Hewner
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
CIS Computer Programming Logic
Intro to Programming Lecture 13
CompSci 100e Program Design and Analysis II January 18, 2011 Prof. Rodger CompSci 100e, Spring20111.
CompSci 100e1.1 Welcome! Program Design and Analysis II for Engineers CompSci 100E French 2231 M, W 2:50-4:05 Professor Jeff Forbes
CPS 100, Spring COMPSCI 100, Spring 2010 Owen Astrachan
Compsci 06/101, Fall COMPSCI 06/101, Fall 2010 Owen Astrachan Robert Duvall
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
(c) University of Washington14-1 CSC 143 Java Collections.
Introduction. 2COMPSCI Computer Science Fundamentals.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Lecture 2: Classes and Objects, using Scanner and String.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
CIT 590 Intro to Programming First lecture on Java.
CPS 100, Fall COMPSCI 100, Fall 2009 Owen Astrachan
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
1 CSC 222: Object-Oriented Programming Spring 2013 Course goals:  To know and use basic Java programming constructs for object- oriented problem solving.
CompSci CompSci 6 Programming Design and Analysis I Dietolf (Dee) Ramm
CompSci 100E 1.1 CompSci 100E Dietolf (Dee) Ramm Robert A. Wagner
CompSci 100E Functions (Static Methods)  Java function.  Takes zero or more input arguments.  Returns one output value.  Applications.  Scientists.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
1 CSC 221: Computer Programming I Spring 2008 course overview  What did we set out to learn?  What did you actually learn?  Where do you go from here?
CompSci 100e1.1 Welcome! Program Design and Analysis II for Engineers CompSci 100E Soc Psy 126 W, F 2:50-4:05 Professor Jeff Forbes
CompSci 100e2.1 Today’s Topics l Reading:  Sedgewick & Wayne: , l Topics  APTs  Basic Collections: ArrayLists: the expandable array.
CompSci Analyzing Algorithms  Consider three solutions to SortByFreqs, also code used in Anagram assignment  Sort, then scan looking for changes.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
CPS APTs and structuring data/information l Is an element in an array, Where is an element in an array?  DIY: use a loop  Use Collections, several.
DATA STRUCTURES (CS212D) Overview & Review Instructor Information 2  Instructor Information:  Dr. Radwa El Shawi  Room: 
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Compsci 06/101, Spring COMPSCI 06/101, Spring 2011 Introduction to Computer Science Owen Astrachan
CPS 100e 5.1 Inheritance and Interfaces l Inheritance models an "is-a" relationship  A dog is a mammal, an ArrayList is a List, a square is a shape, …
CPS What's in Compsci 100? l Understanding tradeoffs: reasoning, analyzing, describing…  Algorithms  Data Structures  Programming  Design l.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Chapter 9 Introduction to Arrays Fundamentals of Java.
 2016, Marcus Biel, ArrayList Marcus Biel, Software Craftsman
CompSci 100 Prog Design and Analysis II
CompSci 100E cs. duke CompSci 100E Dietolf (Dee) Ramm
CSC 222: Object-Oriented Programming
CSC 221: Computer Programming I Spring 2010
CompSci 100 Dietolf (Dee) Ramm
CompSci 6 Introduction to Computer Science
CSC 221: Computer Programming I Fall 2005
JAVA COLLECTIONS LIBRARY
CSC 222: Object-Oriented Programming
CompSci 1: Principles of Computer Science Lecture 1 Course Overview
CSC 321: Data Structures Fall 2018
COMPSCI 100, Spring 2008 Owen Astrachan
Java Basics – Arrays Should be a very familiar idea
Presentation transcript:

CPS 100, Spring COMPSCI 100, Spring 2009 Owen Astrachan

CPS 100, Spring Data into Information and Knowledge Computer Science

CPS 100, Spring What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread which gathers these disparate branches into a single discipline? My answer to these questions is simple --- it is the art of programming a computer. It is the art of designing efficient and elegant methods of getting a computer to solve problems, theoretical or practical, small or large, simple or complex. C.A.R. (Tony)Hoare

CPS 100, Spring Programming != Computer Science l What is the nature of intelligence? How can one predict the performance of a complex system? What is the nature of human cognition? Does the natural world 'compute'? l It is the interplay between such fundamental challenges and the human condition that makes computer science so interesting. The results from even the most esoteric computer science research programs often have widespread practical impact. Computer security depends upon the innovations in mathematics. Your Google search for a friend depends on state-of-the-art distributed computing systems, algorithms, and artificial intelligence.

CPS 100, Spring Efficient design, programs, code Object-oriented design and patterns. Software design principles transcend language, but … Engineer, scientist: what toolkits do you bring to programming? Mathematics, design patterns, libraries --- standard and others… Know data structures and algorithms. Trees, hashing, binary search, sorting, priority queues, greedy methods, graphs … Using the language: Java (or C++, or Python, or …), its idioms, its idiosyncracies

CPS 100, Spring Course Overview l Active Lectures, Recitations, Quizzes, Programs  Recitation based on current assignments and topics Discuss answers, answer new questions, small quiz More opportunities for questions to be answered.  Active Lectures based on readings, questions, programs Online quizzes used to motivate/ensure reading In-class questions used to ensure understanding  Programs Theory and practice of data structures and OO programming Fun, practical, tiring, … Weekly APT programs and longer programs l Exams/Tests  Semester: open book  Final: open book

CPS 100, Spring What's in Compsci 100? l Understanding tradeoffs: reasoning, analyzing, describing…  Algorithms  Data Structures  Programming  Design l Object oriented programming using Java  Eclipse, JDK, Ambient, …  Language, Design Patterns, Design Methodologies …  Problem-solving  From design to code

CPS 100, Spring Questions If you gotta ask, you’ll never know Louis Armstrong: “What’s Jazz?” If you gotta ask, you ain’t got it Fats Waller: “What’s rhythm?” What questions did you ask today? Arno Penzias

CPS 100, Spring Tradeoffs Simple, elegant, quick, efficient: what are our goals in programming? What does XP say about simplicity? Einstein? How do we decide what tradeoffs are important? Tension between generality, simplicity, elegance, … Fast programs, small programs, run anywhere- at-all programs. Runtime, space-time, your time, CPU time… Programming, design, algorithmic, data- structural

CPS 100, Spring From Blog to Scientific Visualization l Text Cloud aka Tag Cloud?  Number of occurrences/emphasis indicated by size of word  Great visual/statistic: l What is involved with generating tag clouds?  Steps? Issues?  See SimpleTagMaker.java

CPS 100, Spring Problem Solving and Programming l How many words are in a file?  What’s a word?  What’s a file?  How do we solve this: simply, quickly, …? What’s the best we can do? Constraints? l How many different/unique words are in a file?  How is this related to previous task? l How many words do two files have in common?  Spell-checking, Google did you mean..?

CPS 100, Spring Fast, cheap, out-of-control? l This is valid and correct Java code, questions? import java.util.*; import java.io.*; public class SimpleUnique { public static void main(String[] args) throws FileNotFoundException{ Scanner s = new Scanner(new File("/data/kjv10.txt")); String[] words = s.useDelimiter("\\Z").next().split("\\s+"); TreeSet set = new TreeSet (); set.addAll(Arrays.asList(words)); System.out.printf("total #: %d, unique #: %d\n", words.length,set.size()); }

CPS 100, Spring How fast is fast? How cheap is cheap? l How do we measure how fast the code/design is?  Can we implement this design in C++?  Can we implement this in Python? l We want a measure that’s independent of language?  What are we measuring?  How do we express answer?  Units? Best case? Average? Worst? l What is answer using recognized terminology? 

CPS 100, Spring What is Computer Science? l Computer science is no more about computers than astronomy is about telescopes. Edsger Dijkstra l Computer science is not as old as physics; it lags by a couple of hundred years. However, this does not mean that there is significantly less on the computer scientist's plate than on the physicist's: younger it may be, but it has had a far more intense upbringing! Richard Feyneman

CPS 100, Spring Some Java Vocabulary and Concepts l Java has a huge standard library  Organized in packages : java.lang, java.util, javax.swing, …  API browseable online, but Eclipse IDE helps a lot l Java methods have different kinds of access inter/intra class  Public methods …  Private methods …  Protected and Package methods … l Primitive types (int, char, double, boolean) are not objects but everything else is literally an instance of class Object  foo.callMe();

CPS 100, Spring Basic data structures and algorithms l Arrays are typed and fixed in size when created  Don't have to fill the array, but cannot expand it  Can store int, double, String, … l ArrayList (and related interface List) grows  Stores objects, not primitives Autoboxing in Java 5 facilitates int to/from Integer conversion  Old code requires casts, ArrayLists typed as storing Objects  ArrayList objects grow themselves intelligently java.util package has lots of data structures and algorithms  Use rather than re-implement, but know how do to do both

CPS 100, Spring Tracking different/unique words l We want to know how many times ‘the’ occurs  Do search engines do this? Does the number of occurrences of “basketball” on a page raise the priority of a webpage in some search engines? Downside of this approach for search engines? l Constraints on solving this problem  We must read every word in the file (or web page)  Search for the word? Avoid counting twice? Store?  Are there fundamental limits on any of these operations? Where should we look for data structure and algorithmic improvements?

CPS 100, Spring Faster? Slower? How does this work? public class SortingUniqueCounter { public static int uniqueCount(String[] list) { Arrays.sort(list); String last = list[0]; int count = 1; // Invariant: count is number of unique words in list[0..k) for (int k = 1; k < list.length; k++) { if (!list[k].equals(last)) { last = list[k] count++; } return count; }

CPS 100, Spring Search: measuring performance l How fast is fast enough? /** true if key in a, else return false */ boolean search(String[] a, String key){ for(int k=0; k < a.length; k++) if (a[k].equals(key)) return true; return false; } l Java details: parameters? Return values? ArrayLists?  See next page for alternate code l How do we measure performance of code? Of algorithm?  Does processor make a difference? Dual-core? Quad-core? 64-bit? Cell processor? …

CPS 100, Spring Six of one and … boolean search(String[] a, String key){ for(int k=0; k < a.length; k++) if (a[k].equals(key)) return true; return false; } boolean search(String[] a, String key){ for(String s : a) if (s.equals(key)) return true; return false; } boolean search(String[] a, String key){ return Arrays.asList(a).indexOf(key) != -1; } l Which is better? By what metric?  Iterable object: array, ArrayList, Set, Map, …  What do we need to call/invoke a method?

CPS 100, Spring Structuring Information: ideas & code l Is an element in an array, Where is an element in an array?  DIY: use a loop  Use Collections, several options  Tradeoffs? public boolean contains(String[] list, String target){ for(String s : list){ if (s.equals(target)) return true; } return false; } public boolean contains(String[] list, String target){ return Arrays.asList(list).contains(target); } public boolean contains(String[] list, String target){ return new HashSet (Arrays.asList(list)).contains(target); }

CPS 100, Spring Class/OO/Java tradeoffs l If you search a list of elements once, you must “touch” every element, so why worry about doing anything else?  Can you skip an element when searching? Why?  What about a sorted list of elements? l If you search repeatedly, it makes sense to organize data  Leverage or amortize the cost of the organization over several searches  Where do we store the organized data so that we can access it repeatedly?

CPS 100, Spring Who is Alan Perlis? l It is easier to write an incorrect program than to understand a correct one l Simplicity does not precede complexity, but follows it l If you have a procedure with ten parameters you probably missed some l If a listener nods his head when you're explaining your program, wake him up l Programming is an unnatural act l Won first Turing award

CPS 100, Spring Computer Science in a Nutshell