Compsci 100, Fall 2009 2.1 Data and Information How and why do we organize data? Differences between data and information? What about knowledge?

Slides:



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

Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
Appendix I Hashing. Chapter Scope Hashing, conceptually Using hashes to solve problems Hash implementations Java Foundations, 3rd Edition, Lewis/DePasquale/Chase21.
CompSci Searching & Sorting. CompSci Searching & Sorting The Plan  Searching  Sorting  Java Context.
CSci 143 Sets & Maps Adapted from Marty Stepp, University of Washington
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
Sets and Maps Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
12-Jul-15 Lists in Java Part of the Collections Framework.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
Chapter 19 Java Data Structures
Collections. Why collections? Collections are used to hold a collection of objects. List holds objects based on order of insertion and can hold non unique.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
CompSci 100 Prog Design and Analysis II Sept 7, 2010 Prof. Rodger 1CompSci 100 Fall 2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
(c) University of Washington14-1 CSC 143 Java Collections.
Compsci 06/101, Fall What will we do today? l Practice solving problems  Solving problems without a computer  Is this different than solving.
1 Concrete collections II. 2 HashSet hash codes are used to organize elements in the collections, calculated from the state of an object –hash codes are.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Collections. The Plan ● Why use collections? ● What collections are available? ● How are the collections different? ● Examples ● Practice.
Chapter 18 Java Collections Framework
1 TCSS 143, Autumn 2004 Lecture Notes Java Collection Framework: Maps and Sets.
Data structures Abstract data types Java classes for Data structures and ADTs.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Sets, Maps and Hash Tables. RHS – SOC 2 Sets We have learned that different data struc- tures have different advantages – and drawbacks Choosing the proper.
Sets and Maps Chris Nevison. Set Interface Models collection with no repetitions subinterface of Collection –has all collection methods has a subinterface.
Compsci 06/101, Fall Vocabulary l What's the Spanish word for 'boy'? 'eat'?  How do you know? l What about the Turkish equivalents?  How do.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
1 Interfaces in Java’s Collection Framework Rick Mercer.
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
Symbol Tables From “Algorithms” (4 th Ed.) by R. Sedgewick and K. Wayne.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
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,
CPS 100, Spring Data and Information How and why do we organize data? Differences between data and information? What about knowledge?
Hash Tables and Hash Maps. DCS – SWC 2 Hash Tables A Set and a Map are both abstract data types – we need a concrete implemen- tation in order to use.
Fall 2015, Kevin Quinn CSE373: Data Structures & Algorithms Lecture 25: Problem Solving CSE373: Data Structures and algorithms1.
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.
Maps Nick Mouriski.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
CPS What's in Compsci 100? l Understanding tradeoffs: reasoning, analyzing, describing…  Algorithms  Data Structures  Programming  Design l.
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Lecture 9:FXML and Useful Java Collections Michael Hsu CSULA.
CompSci 100e 7.1 Plan for the week l Review:  Boggle  Coding standards and inheritance l Understand linked lists from the bottom up and top-down  As.
Introduction to Java Collection. Java Collections What are they? –A number of pre-packaged implementations of common ‘container’ classes, such as LinkedLists,
Building Java Programs Generics, hashing reading: 18.1.
CompSci Toward understanding data structures  What can be put in a TreeSet?  What can be sorted?  Where do we find this information?  How do.
Java: Base Types All information has a type or class designation
Searching, Maps,Tries (hashing)
Data and Information How and why do we organize data? Differences between data and information? What about knowledge?
Java: Base Types All information has a type or class designation
Chapter 19 Java Data Structures
Searching.
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
CSE 373: Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Java String Class String is a class
Introduction to Java Collection
Presentation transcript:

Compsci 100, Fall Data and Information How and why do we organize data? Differences between data and information? What about knowledge?

Compsci 100, Fall Organizing Data: ideas and issues l Often there is a time/space tradeoff  If we use more space (memory) we can solve a data/information problem in less time: time efficient  If we use more more time, we can solve a data/information problem with less space: space efficient l Search v Store: repeating the same thing again …  We’re not “smart” enough to avoid the repetition Learn new data structures or algorithms!  The problem is small enough or done infrequently enough that being efficient doesn’t matter  Markov illustrates this (next assignment)

Compsci 100, Fall Map: store pairs of (key,value) l Search engine: web pages for “clandestine”  Key: word or phrase, value: list of web pages  This is a map: search query->web pages l DNS: domain name duke.edu  IP:  Key: domain name, value: IP address  This is a map: domain name->IP address l Map (aka table, hash) associates keys with values  Insert (key,value) into map, iterate over keys or pairs  Retrieve value associated with a key, remove pair

Compsci 100, Fall Maps, another point of view An array is a map, consider array arr  The key is an index, say i, the value is arr[i]  Values stored sequentially/consecutively, not so good if the keys/indexes are 1, 100, and 1000, great if 0,1,2,3,4,5 l Time/space trade-offs in map implementations, we’ll see more of this later  TreeMap: most operations take time log(N) for N-elements  HashMap: most operations are constant time on average Time for insert, get, … doesn’t depend on N (wow!)  But! Elements in TreeMap are in order and TreeMap uses less memory than HashMap

Compsci 100, Fall Map (foreshadowing or preview) Any kind of Object can be inserted as a key in a HashMap  But, performance might be terrible if hashValue isn’t calculated well  Every object has a different number associated with it, we don’t want every object to be associated with 37, we want things spread out Only Comparable object can be key in TreeMap  Basically compare for less than, equal, or greater  Some objects are naturally comparable: String, Integer  Sometimes we want to change how objects are compared  Sometimes we want to invent Comparable things

Compsci 100, Fall Traceroute: where’s the map here? traceroute traceroute to katahdin.cs.dartmouth.edu ( ), 64 hops max, 1 lou ( ) ms ( ) ms 3 tel1sp-roti.netcom.duke.edu ( ) ms 4 rlgh7600-gw-to-duke7600-gw.ncren.net ( ) ms 5 rlgh1-gw-to-rlgh7600-gw.ncren.net ( ) ms 6 rtp11-gw-to-rpop-oc48.ncren.net ( ) ms 7 rtp7600-gw-to-rtp11-gw-sec.ncren.net ( ) ms 8 dep7600-gw2-to-rtp7600-gw.ncren.net ( ) ms 9 internet2-to-dep7600-gw2.ncren.net ( ) ms 10 ge nycmng.abilene.ucaid.edu ( ) ms 11 so rtr.newy.net.internet2.edu ( ) ms 12 nox300gw1-vl-110-nox-internet2.nox.org ( ) ms 13 … 14 … 15 border.ropeferry1-crt.dartmouth.edu ( ) ms 16 katahdin.cs.dartmouth.edu ( ) ms

Compsci 100, Fall John von Neumann “Anyone who attempts to generate random numbers by deterministic means is, of course, living in a state of sin.” “There's no sense in being precise when you don't even know what you're talking about. “ “There are two kinds of people in the world: Johnny von Neumann and the rest of us.” Eugene Wigner, Noble Physicist

Compsci 100, Fall Interface at work: Frequencies.java l From recitation: key is a string, value is # occurrences  Code below is slightly modified version of recitation code What clues for prototype of map.get and map.put ?  What if a key is not in map, what value returned?  What kind of objects can be put in a map?  Kinds of maps? for(String s : words) { s = s.toLowerCase(); Integer count = map.get(s); if (count == null){ map.put(s,1); } else{ map.put(s,count+1); }

Compsci 100, Fall Coding Interlude: FrequenciesSorted Nested classes in FrequenciesSorted  WordPair : combine word and count together, why?  WPFreq : allows WordPair objects to be compared by freq How are WordPair objects created?  In doFreqsA is the comparable-ness leveraged?  What about in sorting? Alternative in doFreqsB  Use TreeMap, then ArrayList then sort, why?  Is comparable-ness leveraged? Sorting?

Compsci 100, Fall What can an Object do (to itself)? l  Look at java.lang.Object  What is this class? What is its purpose? l toString()  Used to print ( System.out.println ) an object  overriding toString() useful in new classes  String concatenation: String s = "value "+ x;  Default is basically a pointer-value

Compsci 100, Fall What else can you do to an Object? l equals(Object o)  Determines if guts of two objects are the same, must override, e.g., for using a.indexOf(o) in ArrayList a  Default is ==, pointer equality l hashCode()  Hashes object (guts) to value for efficient lookup l If you're implementing a new class, to play nice with others you must  Override equals and hashCode  Ensure that equal objects return same hashCode value

Compsci 100, Fall Objects and values l Primitive variables are boxes  think memory location with value l Object variables are labels that are put on boxes String s = new String("genome"); String t = new String("genome"); if (s == t) {they label the same box} if (s.equals(t)) {contents of boxes the same} s t What's in the boxes? "genome" is in the boxes

Compsci 100, Fall Objects, values, classes l For primitive types: int, char, double, boolean  Variables have names and are themselves boxes (metaphorically)  Two int variables assigned 17 are equal with == l For object types: String, ArrayList, others  Variables have names and are labels for boxes  If no box assigned, created, then label applied to null  Can assign label to existing box (via another label)  Can create new box using built-in new l Object types are references/pointers/labels to storage

Compsci 100, Fall Anatomy of a class public class Foo { private int mySize; private String myName; public Foo(){ // what’s needed? } public int getSize(){ return mySize; } public double getArea(){ double x; x = Math.sqrt(mySize); return x; } l What values for vars (variables) and ivars (instance variables)?

Compsci 100, Fall David Parnas "For much of my life, I have been a software voyeur, peeking furtively at other people's dirty code. Occasionally, I find a real jewel, a well-structured program written in a consistent style, free of kludges, developed so that each component is simple and organized, and designed so that the product is easy to change. "

Compsci 100, Fall Parnas on re-invention "We must not forget that the wheel is reinvented so often because it is a very good idea; I've learned to worry more about the soundness of ideas that were invented only once. "

Compsci 100, Fall David Parnas (entry in Wikipedia)Wikipedia l Module Design: Parnas wrote about the criteria for designing modules, in other words, the criteria for grouping functions together. This was a key predecessor to designing objects, and today's object-oriented design. l Social Responsibility: Parnas also took a key stand against the Strategic Defense Initiative (SDI) in the mid 1980s, arguing that it would be impossible to write an application that was free enough from errors to be safely deployed.Strategic Defense Initiative l Professionalism: He believes that software engineering is a branch of traditional engineering.

Compsci 100, Fall Tomato and Tomato, how to code java.util.Collection and java.util.Collections  one is an interface add(), addAll(), remove(), removeAll(), clear() toArray(), size(), iterator()  one is a collection of static methods sort(), shuffle(), reverse(), max() frequency(), indexOfSubList () java.util.Arrays  Also a collection of static methods sort(), fill(), binarySearch(), asList()