Compsci 201, Maps+Hashing
|
|
- Melinda Maxwell
- 6 years ago
- Views:
Transcription
1 Compsci 201, Maps+Hashing Owen Astrachan Jeff Forbes September 13, /15/17 Compsci 201, Fall 2017, Maps/Hashing 1
2 Plan for the Day Extend Fast ClassScores solution to Not just values in [0..100], not just integers Motivate the java.util.map interface, hashing How does hashing work: in general, in Java Mapping objects to numbers Coping with collisions Implementing the Map interface: OO concept 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 2
3 Logistics Interlude 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 3
4 On Being (Close to) Done 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 4
5 F is for Folder aka Directory where things are stored in Git FIFO How a Queue works, and not a Stack Floating Point What is a double in Java Function Abstraction a method in Java 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 5
6 Re-orientation from Wednesday Using ClassScores to equate counter[32] with frequency[ policy ] Counting number of occurrences of 32 Counting number of occurrences of policy In Java we can t use strings to index an array, but we can use strings to index a Map Keys in a map are immutable Values don t have to be integers, anything! 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 6
7 Thinking about Efficiency ClassScores code: Review code that created int[] of 101 counters Index into array was mapped to # occurrences counters[30] is number of times 30 appears Access counters[99] fast! Same as counters[1024] Same as counters[index] Any value of index! Constant time indexing in arrays 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 7
8 Counting words Look for search trends in Google? Look for authorship based on statistics? We d like a fast solution, just as counters[32] is # of occurrences of 32, scount[ policy ] could be # of occurrences of policy Languages like Python allow this syntax! Languages like Java require alternate syntax Map aka Hash aka Dictionary 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 8
9 A Rose by Any Other Name 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 9
10 Compare two approaches the fox cried fat tears Parallel arrays: word[k] occurs count[k] times What do you do when reading a word? Look up in words, increment parallel location Map index to values in two arrays (ArrayLists) 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 10
11 Using parallel arrays MethodA in Read string, find index in ArrayList words If found, increment value at index in counter Else new word? Add at end of words/counter the fox cried fat tears /15/17 Compsci 201, Fall 2017, Maps/Hashing 11
12 Compare Similar Approach MethodB Similar to parallel arrays, but using one structure Store (String,Integer) or (word, # occurrences) Fast lookup by String, update # occurrences Store (key,value): lookup by key, obtain value How to make this fast? Stay tuned for details! Bottleneck in MethodA? indexof method 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 12
13 Map conceptually (key,value) Search engine: (K,V) is (query, list of web pages) Key is word or phrase, Value: list of pages Maps query to list of web pages/urls Color Name/RGB triple: (K,V) is (name, (r,g,b)) Duke Blue maps to (0,0,156) Dartmouth Green maps to (0,105,62) Stanford Cardinal maps to (140,21,21) 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 13
14 We use java.util.map HashMap<Key,Value> or TreeMap<K,V> Nested/inner class Map.Entry<K,V> Method return purpose Map.size() int # keys Map.keySet() Set<K> Set of keys Map.values() Collection<V> All values Map.containsKey(K) boolean Is key in Map? Map.put(K,V) V (ignored) Insert (K,V) Map.entrySet() Set<Map.Entry> Get (K,V) pairs Map.clear() void Remove all keys 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 14
15 Examining Map Code Why initialize value to 0 when stored in map? What does map.get(key) return? What does map.put(key,value) do? HashMap<String,Integer> map = new HashMap<>(); Scanner s = new Scanner(new File(f)); while (s.hasnext()){ String w = s.next(); if (! map.containskey(w)) { map.put(w, 0); } map.put(w, map.get(w) + 1); } // map complete here 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 15
16 Thinking about Maps and Tradeoffs Looking at more than one approach 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 16
17 HashSet<> and HashMap<> Underneath same concept: hash table HashSet actually implemented with HashMap Keys are unique, all mapped to same value, that value is ignored Read API: il/hashmap.html 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 17
18 Abstract View of Hashing Every object knows where it belongs in a hash table, just as 39 is index into counters[39] Ask object like tiger where it belongs Ask any object of any class where it belongs Call hashcode, get an int value 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 18
19 What does hashcode return? Ideally: an integer that ranges over all possible values for a locker that stores objects Hash table is an array, hashcode like an index IRL? Math.abs(hashCode())% ht.length What if every object returns 15? Or more than one does? Collisions will happen! Conceptually what s in a locker? Room for stuff 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 19
20 Ideal world? Real world! 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 20
21 The hashcode contract Every object has.hashcode() method Inherited from Object, but typically overridden What does inherit mean? Override mean? Must respect.equals(): If a.equals(b)? a.hashcode() == b.hashcode() Converse not true! There will be collisions 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 21
22 What s a HashTable? Indexable structure, like row of lockers ArrayList rather than array so it can grow Constant time to find a locker given the number: locker 2 same as locker ArrayList< > of what? What s in the locker Able to store several elements: ArrayList! ArrayList<ArrayList<String>> Coping with collisions in a simple way 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 22
23 Alternate Ideas? One object per locker, if full? Try next one Linear probing, has it s own issues (# lockers?) Use better structures per locker Low-level linked lists (up until Java 8) Low-level search trees (Java 8) Deal with worst-case, generate good average case performance 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 23
24 Maria Klawe President of Harvey Mudd Dean of Engineering at Princeton, ACM Fellow, College Dropout (and re-enroller) I personally believe that the most important thing we have to do today is use technology to address societal problems, especially in developing regions Coding is today's language of creativity. All our children deserve a chance to become creators instead consumers of computer science. 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 24
25 Hashing and Maps Use maps to solve problems Create maps, understand API HashMap<Key,Value> or TreeMap<Key,Value> Tradeoff of speed v order à orderable! Understand hashing and performance Create your own HashMap! Complicated by <Key,Value>, study via sets 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 25
26 DIY Set with ArrayList First we look at ArraySet.java and SetDriver.java Add an element? Search, then add if not found More elements added? Slower.add is Desktop Laptop 4103 words of from data/melville.txt in words of from data/hawthorne.txt in words of from data/kjv10.txt in words of from data/melville.txt in words of from data/hawthorne.txt in words of from data/kjv10.txt in /15/17 Compsci 201, Fall 2017, Maps/Hashing 26
27 ArraySet deconstructed This class has a generic parameter <Type> Could be <Foo>, use like ArrayList<String> Implementations of.contains,.remove use loop Could use ArrayList equivalent methods! Examine.add: 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 27
28 DIY Set, SimpleHashSet Look at SimpleHashSet and compare ArraySet What is an element of ArrayList myelements? ArraySet 4103 words of from data/melville.txt in words of from data/hawthorne.txt in words of from data/kjv10.txt in SimpleHashSet 4103 words of from data/melville.txt in words of from data/hawthorne.txt in words of from data/kjv10.txt in /15/17 Compsci 201, Fall 2017, Maps/Hashing 28
29 SimpleHashSet Deconstructed Constructor adds 10,000 ArrayLists Alternatives to constructor? What if 10,000 changes to 1,000 or 100 or 10 Helper method.gethash Used:.contains(),.remove(),.add() 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 29
30 Interplay of.hashcode/.equals Use StringWrapper class to help understand Static variables that count calls of methods When is.hashcode called? When is.equals called? What is interplay between these? Change size of hash table and see what happens! What calls change, why do they change? 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 30
31 Thinking about Hashing What does StringWrapper help us understand? 9/15/17 Compsci 201, Fall 2017, Maps/Hashing 31
Hash tables. hashing -- idea collision resolution. hash function Java hashcode() for HashMap and HashSet big-o time bounds applications
hashing -- idea collision resolution Hash tables closed addressing (chaining) open addressing techniques hash function Java hashcode() for HashMap and HashSet big-o time bounds applications Hash tables
More informationMore Java Basics. Jeff Forbes Owen Astrachan September 8, /8/17 Compsci 201, Fall 2017, Java Basics 1
More Java Basics Jeff Forbes Owen Astrachan September 8, 2017 9/8/17 Compsci 201, Fall 2017, Java Basics 1 D is for Debugging A key skill in making your programs run Data-first Data dictates the tradeoffs
More informationUSAL1J: Java Collections. S. Rosmorduc
USAL1J: Java Collections S. Rosmorduc 1 A simple collection: ArrayList A list, implemented as an Array ArrayList l= new ArrayList() l.add(x): adds x at the end of the list l.add(i,x):
More informationData Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada
CS102 Hash Tables Prof. Tejada 1 Vectors, Linked Lists, Stack, Queues, Deques Can t provide fast insertion/removal and fast lookup at the same time The Limitations of Data Structure Binary Search Trees,
More informationData Structures. COMS W1007 Introduction to Computer Science. Christopher Conway 1 July 2003
Data Structures COMS W1007 Introduction to Computer Science Christopher Conway 1 July 2003 Linked Lists An array is a list of elements with a fixed size, accessed by index. A more flexible data structure
More information11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures
Collections CSE 143 Java Collections Most programs need to store and access collections of data Collections are worth studying because... They are widely useful in programming They provide examples of
More informationCS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016
Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016 There are 7 problems on the exam, with 50 points total available. There are 8 pages to the exam (4 pages double-sided),
More informationAnnouncements. Today s topic: Hashing (Ch. 10) Next topic: Graphs. Break around 11:45am
Announcements Today s topic: Hashing (Ch. 10) Next topic: Graphs Break around 11:45am 1 Container structures so far Array lists O(1) access O(n) insertion/deletion (average case), better at end Linked
More informationCompsci 201 Hashing. Jeff Forbes February 7, /7/18 CompSci 201, Spring 2018, Hashiing
Compsci 201 Hashing Jeff Forbes February 7, 2018 1 G is for Garbage Collection Nice to call new and not call delete! Git Version control that's so au courant GPL First open source license Google How to
More informationHash Table. Ric Glassey
Hash Table Ric Glassey glassey@kth.se Overview Hash Table Aim: Describe the map abstract data type with efficient insertion, deletion and search operations Motivation: List data structures are divided
More informationAnnouncements. Container structures so far. IntSet ADT interface. Sets. Today s topic: Hashing (Ch. 10) Next topic: Graphs. Break around 11:45am
Announcements Today s topic: Hashing (Ch. 10) Next topic: Graphs Break around 11:45am Container structures so far Array lists O(1) access O(n) insertion/deletion (average case), better at end Linked lists
More informationEXAMINATIONS 2016 TRIMESTER 2
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2016 TRIMESTER 2 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS
More informationTutorial #11 SFWR ENG / COMP SCI 2S03. Interfaces and Java Collections. Week of November 17, 2014
Tutorial #11 SFWR ENG / COMP SCI 2S03 Interfaces and Java Collections Week of November 17, 2014 Interfaces An interface defines a specification or contract that a class must meet to be defined as an instance
More informationStandard 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 informationTHE WEB. Document IDs. Index & Freq s. Search engine servers. user query. Rank results. crawl the web. Create word index. i do not like them
Rank results user query Document IDs Search engine servers crawl the web Create word index Index & Freq s THE WEB i am sam i am sam sam i am that sam i am that sam i am i do not like that sam i am do you
More informationThe class Object. Lecture CS1122 Summer 2008
The class Object http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html Lecture 10 -- CS1122 Summer 2008 Review Object is at the top of every hierarchy. Every class in Java has an IS-A relationship
More informationFinding Maximally Occurring Word. PFTD and toward the week. Finding maximally occurring word. Thinking about methoda
PFTD and toward the week Be able to articulate why 201 is the right course for you, in terms of being able to complete it with understanding Be able to explain what work is expected, collaboration policies,
More informationFall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up
CSM B Heaps & Hashing Fall 0 Mentoring : October 3, 0 Min-Heapify This. In general, there are 4 ways to heapify. Which ways actually work? Level order, bubbling up Level order, bubbling down Reverse level
More informationCSC 321: Data Structures. Fall 2017
CSC : Data Structures Fall 7 Hash tables HashSet & HashMap hash table, hash function collisions Ø linear probing, lazy deletion, clustering, rehashing Ø chaining Java hashcode method HW6: finite state
More informationCS61BL Summer 2013 Midterm 2
CS61BL Summer 2013 Midterm 2 Sample Solutions + Common Mistakes Question 0: Each of the following cost you.5 on this problem: you earned some credit on a problem and did not put your five digit on the
More informationHASH TABLE BY AKARSH KUMAR
HASH TABLE BY AKARSH KUMAR HASH TABLE PURPOSE The purpose of a HashTable is to serve as an ArrayList type object that has O(1) set, get, and lookup times. It also maps keys to values and includes put and
More informationMidterm Exam 2 CS 455, Spring 2015
Name: USC NetId (e.g., ttrojan): Midterm Exam 2 CS 455, Spring 2015 April 7, 2015 There are 7 problems on the exam, with 60 points total available. There are 8 pages to the exam, including this one; make
More informationFamily Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013
Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Model Solutions COMP 103: Test
More informationRecap. List Types. List Functionality. ListIterator. Adapter Design Pattern. Department of Computer Science 1
COMP209 Object Oriented Programming Container Classes 3 Mark Hall List Functionality Types List Iterator Adapter design pattern Adapting a LinkedList to a Stack/Queue Map Functionality Hashing Performance
More information[1] Strings, Arrays, Pointers, and Hashing
[1] Strings, Arrays, Pointers, and Hashing Quick Tips Try solving these problems on your own (without the thought of trying to program them). Then, once you find a pattern, code it Thoroughly test your
More information27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection
Objectives Collection Collections Framework Concrete collections Collection algorithm By Võ Văn Hải Faculty of Information Technologies Summer 2012 Legacy collection 1 2 2/27 Collections Framework "Collection"
More informationAssignment 4: Hashtables
Assignment 4: Hashtables In this assignment we'll be revisiting the rhyming dictionary from assignment 2. But this time we'll be loading it into a hashtable and using the hashtable ADT to implement a bad
More informationEXAMINATIONS 2017 TRIMESTER 2
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2017 TRIMESTER 2 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS
More informationCollections, Maps and Generics
Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.
More informationMenu cs2220: Engineering Software
Menu cs2220: Engineering Software PS2 Questions ArrayList Class 5: Validation Software Validation Fall 2010 University of Virginia David Evans List Datatype Lists in Scheme: Either (1) null or (2) a Pair
More informationIntroduction 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 informationCS 106A, Lecture 20 ArrayLists and HashMaps
CS 106A, Lecture 20 ArrayLists and HashMaps suggested reading: Java Ch. 13.2 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License.
More informationReview. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( )
Review CSE 143 Java Hashing Want to implement Sets of objects Want fast contains( ), add( ) One strategy: a sorted list OK contains( ): use binary search Slow add( ): have to maintain list in sorted order
More informationEXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS
T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 2 COMP103 INTRODUCTION
More informationCS2110: Software Development Methods. Maps and Sets in Java
CS2110: Software Development Methods Maps and Sets in Java These slides are to help with the lab, Finding Your Way with Maps Today s lab uses Maps (and Sets but just a little). Readings from textbook:
More informationDUKE UNIVERSITY Department of Computer Science. Test 2: CompSci 100
DUKE UNIVERSITY Department of Computer Science Test 2: CompSci 100 Name (print): Community Standard acknowledgment (signature): Problem 1 value 14 pts. grade Problem 2 9 pts. Problem 3 7 pts. Problem 4
More informationCSC 321: Data Structures. Fall 2016
CSC : Data Structures Fall 6 Hash tables HashSet & HashMap hash table, hash function collisions Ø linear probing, lazy deletion, primary clustering Ø quadratic probing, rehashing Ø chaining HashSet & HashMap
More informationEXAMINATIONS 2012 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2012 MID YEAR COMP103 Introduction to Data
More informationCS11 Java. Winter Lecture 8
CS11 Java Winter 2010-2011 Lecture 8 Java Collections Very powerful set of classes for managing collections of objects Introduced in Java 1.2 Provides: Interfaces specifying different kinds of collections
More informationHashing. It s not just for breakfast anymore! hashing 1
Hashing It s not just for breakfast anymore! hashing 1 Hashing: the facts Approach that involves both storing and searching for values (search/sort combination) Behavior is linear in the worst case, but
More informationCollections Questions
Collections Questions https://www.journaldev.com/1330/java-collections-interview-questions-and-answers https://www.baeldung.com/java-collections-interview-questions https://www.javatpoint.com/java-collections-interview-questions
More informationAdam Blank Lecture 9 Autumn 2016 CSE 143. Computer Programming II
Adam Blank Lecture 9 Autumn 2016 CSE 143 Computer Programming II CSE 143: Computer Programming II Sets and Maps Outline 1 Sets 2 Foreach Loops 3 Maps Alice in Wonderland 1 Count the Number of Distinct
More informationBeside List, there are two other common collections. Set: like a mathematical set, unordered, no repetitions.
Collections Beside List, there are two other common collections. Set: like a mathematical set, unordered, no repetitions. Map: Indexes collections by arbitrary keys. HashSet import java.util.hashset;
More information5/23/2015. Core Java Syllabus. VikRam ShaRma
5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5
More informationDomain-Driven Design Activity
Domain-Driven Design Activity SWEN-261 Introduction to Software Engineering Department of Software Engineering Rochester Institute of Technology Entities and Value Objects are special types of objects
More informationAlgorithms. Produced by. Eamonn de Leastar
Algorithms Produced by Eamonn de Leastar (edeleastar@wit.ie) Collections ± Collections Architecture ± Definition ± Architecture ± Interfaces ± Collection ± List ± Set ± Map ± Iterator ± Implementations
More informationCS 310: Maps and Sets and Trees
CS 310: Maps and Sets and Trees Chris Kauman Week 8-2 Logistics Oce hours Wednesday normal: 4:30-5:30pm Thursday 2-3pm special oce hours Reading Weiss Ch. 6 (Java Library Classes/Interfaces) 6.7 Sets,
More informationCS 310: Hashing Basics and Hash Functions
CS 310: Hashing Basics and Hash Functions Chris Kauffman Week 6-1 Logistics HW1 Final due Saturday Discuss setfill(x) O(1) implementation Reminder: ANALYSIS.txt and efficiency of expansion Questions? Midterm
More informationJava Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar
Java Classes Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie
More informationJava Collections Framework. 24 April 2013 OSU CSE 1
Java Collections Framework 24 April 2013 OSU CSE 1 Overview The Java Collections Framework (JCF) is a group of interfaces and classes similar to the OSU CSE components The similarities will become clearly
More informationCS61B Lecture #24: Hashing. Last modified: Wed Oct 19 14:35: CS61B: Lecture #24 1
CS61B Lecture #24: Hashing Last modified: Wed Oct 19 14:35:49 2016 CS61B: Lecture #24 1 Back to Simple Search Linear search is OK for small data sets, bad for large. So linear search would be OK if we
More informationTest 1 Fall 2018 : Compsci 201
Test 1 Fall 2018 : Compsci 201 Owen Astrachan September 26, 2018 Name: NetID/Login: (1 point) Community standard acknowledgment (signature) (1 point) Problem 1 value 28 pts. grade Problem 2 9 pts. Problem
More informationCSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1
Review from Lecture 21 CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 the single most important data structure known to mankind Hash Tables, Hash Functions,
More informationLecture 17: Implementing HashTables 10:00 AM, Mar 5, 2018
CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lecture 17: Implementing HashTables 10:00 AM, Mar 5, 2018 1 Implementing Hashtables 1 1.1 Understanding Collisions..................................
More informationNot overriding equals
Not overriding equals what happens if you do not override equals for a value type class? all of the Java collections will fail in confusing ways 1 Not overriding equals Complex y = new Complex(1, -2);
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:
More informationInterfaces and Collections
Interfaces and Collections COMPSCI 2S03 Mikhail Andrenkov Department of Computing and Software McMaster University Week 9: November 14-18 Mikhail Andrenkov Interfaces and Collections 1 / 25 Outline 1 Interfaces
More informationObject Oriented Programming and Design in Java. Session 19 Instructor: Bert Huang
Object Oriented Programming and Design in Java Session 19 Instructor: Bert Huang Announcements Homework 4 due MONDAY. Apr. 19 No multithreading in programming part Review Deadlocks and the Dining Philosophers
More informationSolutions to Quiz 1 (March 14, 2016)
MIT 6.005: Software Construction Max Goldman revised Wednesday 16 th March, 2016, 14:08 Solutions to Quiz 1 (March 14, 2016) Problem 1 (Multiple Choice) (20 points). (a) Which of the following must be
More informationMenu. In general, what are possible advantages of one design over another? Class 27: Exam 2. Exam 2 Parenthesizing the Expression. Design A.
cs2220: Engineering Software Class 27: Exam 2 Menu Exam 2 Parenthesizing the Expression Fall 2010 UVa David Evans Design A Design B In general, what are possible advantages of one design over another?
More informationAnnouncements. Submit Prelim 2 conflicts by Thursday night A6 is due Nov 7 (tomorrow!)
HASHING CS2110 Announcements 2 Submit Prelim 2 conflicts by Thursday night A6 is due Nov 7 (tomorrow!) Ideal Data Structure 3 Data Structure add(val x) get(int i) contains(val x) ArrayList 2 1 3 0!(#)!(1)!(#)
More informationComputer Science II (Spring )
Computer Science II 4003-232-01 (Spring 2007-2008) Week 5: Generics, Java Collection Framework Richard Zanibbi Rochester Institute of Technology Generic Types in Java (Ch. 21 in Liang) What are Generic
More informationCS2110: Software Development Methods. Maps and Sets in Java
CS2110: Software Development Methods Maps and Sets in Java These slides are to help with the lab, Finding Your Way with Maps This lab uses Maps, and Sets too (but just a little). Readings from textbook:
More information1. Suppose you are using a HashMap<String,Integer>. What is the runtime of put and get assuming you have a reasonable hash function?
Data Structures Brett Bernstein Lecture 10: BitSets and Packages Exercises 1. Suppose you are using a HashMap. What is the runtime of put and get assuming you have a reasonable hash function?
More informationCSE 143X. Accelerated Computer Programming I/II
Adam Blank Lecture 17 Autumn 2015 CSE 143X Accelerated Computer Programming I/II CSE 143X: Accelerated Computer Programming I/II Sets and Maps Outline 1 Languages and Grammars 2 Sets 3 Foreach Loops 4
More informationFaculty of Science FINAL EXAMINATION
Faculty of Science FINAL EXAMINATION COMPUTER SCIENCE COMP 250 INTRODUCTION TO COMPUTER SCIENCE Examiner: Prof. Michael Langer April 27, 2010 Associate Examiner: Mr. Joseph Vybihal 9 A.M. 12 P.M. Instructions:
More informationCOMP 103 Introduction to Data Structures and Algorithms
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:..................... EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data
More informationCS 3410 Ch 20 Hash Tables
CS 341 Ch 2 Hash Tables Sections 2.1-2.7 Pages 773-82 2.1 Basic Ideas 1. A hash table is a data structure that supports insert, remove, and find in constant time, but there is no order to the items stored.
More informationMaps,Hash(es) We need more second year reps
Maps,Hash(es) We need more second year reps Your on the run from the police and a shadowy secret government organization keen to kill you (it happens) Real card/fake card Eve former co-worker has given
More informationCONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17
List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code
More informationC12a: The Object Superclass and Selected Methods
CISC 3115 TY3 C12a: The Object Superclass and Selected Methods Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/4/2018 CUNY Brooklyn College 1 Outline The Object class and
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 7 : Collections Lecture Contents 2 Why collections? What is a collection? Non-generic collections: Array & ArrayList Stack HashTable
More informationObject-Oriented Programming
13 Object-Oriented Programming Exercises 13.1 Using Java as an example: 13.2 Code reuse: inhertiance, interfaces. In the case of an interface, any class implementing the Comparable interface can be sorted
More informationIntroduction hashing: a technique used for storing and retrieving information as quickly as possible.
Lecture IX: Hashing Introduction hashing: a technique used for storing and retrieving information as quickly as possible. used to perform optimal searches and is useful in implementing symbol tables. Why
More informationIntroducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved
Introducing Hashing Chapter 21 Contents What Is Hashing? Hash Functions Computing Hash Codes Compressing a Hash Code into an Index for the Hash Table A demo of hashing (after) ARRAY insert hash index =
More informationTopic 10: The Java Collections Framework (and Iterators)
Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationMIDTERM EXAM THURSDAY MARCH
Week 6 Assignments: Program 2: is being graded Program 3: available soon and due before 10pm on Thursday 3/14 Homework 5: available soon and due before 10pm on Monday 3/4 X-Team Exercise #2: due before
More informationEXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I ÎÍÏ V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data Structures and Algorithms Time Allowed:
More informationCS 520 Theory and Practice of Software Engineering Fall 2018
Logistics CS 520 Theory and Practice of Software Engineering Fall 2018 Best and worst programming practices September 11, 2018 Reminder Recap: software architecture vs. design Class website: https://people.cs.umass.edu/~brun/class/2018fall/cs520/
More informationIntroduction to Hashing
Lecture 11 Hashing Introduction to Hashing We have learned that the run-time of the most efficient search in a sorted list can be performed in order O(lg 2 n) and that the most efficient sort by key comparison
More informationAbstract Data Types (ADTs) Queues & Priority Queues. Sets. Dictionaries. Stacks 6/15/2011
CS/ENGRD 110 Object-Oriented Programming and Data Structures Spring 011 Thorsten Joachims Lecture 16: Standard ADTs Abstract Data Types (ADTs) A method for achieving abstraction for data structures and
More informationCS 310: Maps and Sets
CS 310: Maps and Sets Chris Kauffman Week 9-1 Logistics Goals Today HW2 Discussion Maps and Sets HW2 Discussion Milestones due Thu 7/6 Discuss AdditiveList Iterator Implementation O(1) Undo/Redo Reading
More information(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other?
CSM B Hashing & Heaps Spring 0 Week 0: March 0, 0 Motivation. (a) In the worst case, how long does it take to index into a linked list? Θ(N) (b) In the worst case, how long does it take to index into an
More informationCSC 321: Data Structures. Fall 2016
CSC 321: Data Structures Fall 2016 Balanced and other trees balanced BSTs: AVL trees, red-black trees TreeSet & TreeMap implementations heaps priority queue implementation heap sort 1 Balancing trees recall:
More informationCSC 321: Data Structures. Fall 2017
CSC 321: Data Structures Fall 2017 Balanced and other trees balanced BSTs: AVL trees, red-black trees TreeSet & TreeMap implementations heaps priority queue implementation heap sort 1 Balancing trees recall:
More informationCS 520 Theory and Practice of Software Engineering Fall 2017
Logistics CS 520 Theory and Practice of Software Engineering Fall 2017 Best and worst programming practices September 12, 2017 Recap: software architecture vs. design Recap: software architecture examples
More informationCSE373 Fall 2013, Second Midterm Examination November 15, 2013
CSE373 Fall 2013, Second Midterm Examination November 15, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please
More informationCS 520 Theory and Practice of Software Engineering Fall 2017
CS 520 Theory and Practice of Software Engineering Fall 2017 Best and worst programming practices September 12, 2017 Logistics Recap: software architecture vs. design Specification Architecture Development
More informationCsci 102: Sample Exam
Csci 102: Sample Exam Duration: 65 minutes Name: NetID: Student to your left: Student to your right: DO NOT OPEN THIS EXAM UNTIL INSTRUCTED Instructions: Write your full name and your NetID on the front
More informationAdam Blank Lecture 5 Winter 2019 CS 2. Introduction to Programming Methods
Adam Blank Lecture 5 Winter 2019 CS 2 Introduction to Programming Methods CS 2: Introduction to Programming Methods Java Collections Abstract Data Types (ADT) 1 Abstract Data Type An abstract data type
More informationMarkov - Compsci 201
Markov - Compsci 201 The code for this assignment is available through snarf (assignment/markov) as well as on the course webpage. Java Help You should expect to take some time getting used to the Java
More informationProblem 1: Building and testing your own linked indexed list
CSCI 200 Lab 8 Implementing a Linked Indexed List In this lab, you will be constructing a linked indexed list. You ll then use your list to build and test a new linked queue implementation. Objectives:
More information10 Java Collections; Equality, JUnit
10 Java Collections; Equality, JUnit Activities 1. Familiarize yourself with some of the Java Collections Framework. 2. Learn the basics of overriding the hashcode and equals methods. 3. Learn the basics
More informationCollections (Java) Collections Framework
Collections (Java) https://docs.oracle.com/javase/tutorial/collections/index.html Collection an object that groups multiple elements into a single unit. o store o retrieve o manipulate o communicate o
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 8 : Collections Lecture Contents 2 Why collections? What is a collection? Non-generic collections: Array & ArrayList Stack HashTable
More informationCollections class Comparable and Comparator. Slides by Mark Hancock (adapted from notes by Craig Schock)
Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections
More informationLecture 15 Summary. Collections Framework. Collections class Comparable and Comparator. Iterable, Collections List, Set Map
Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections
More informationPrimitives, Objects, and Heap/Stack Review 1 Chris Piech CS106A, Stanford University
Primitives, Objects, and Heap/Stack Review 1 Chris Piech CS106A, Stanford University 1 Plan for today Announcements/Exam logistics Tracing 1D Arrays 2D Arrays ArrayList Plan for tomorrow Announcements/Exam
More information1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1
Ba Arrays Arrays A normal variable holds value: An array variable holds a collection of values: 4 Naming arrays An array has a single name, so the elements are numbered or indexed. 0 3 4 5 Numbering starts
More information