Homework 4: Hash Tables Due: 5:00 PM, Mar 9, 2018

Size: px
Start display at page:

Download "Homework 4: Hash Tables Due: 5:00 PM, Mar 9, 2018"

Transcription

1 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Homework 4: Hash Tables Due: 5:00 PM, Mar 9, DIY Grep 2 2 Chaining Hash Tables 4 3 Hash Table Iterator 5 Objectives By the end of this homework, you will know: ˆ how to iterate over the elements a hash table By the end of this homework, you will be able to: ˆ implement a hash table ˆ use hash tables to represent sets (as well as dictionaries) How to Hand In For this (and all) homework assignments, you should hand in answers for all the non-practice questions. For this homework specifically, this entails answering the Hash Tables, Hash Table Iterator, and DIY Grep questions. In order to hand in your solutions to these problems, they must be stored in appropriately-named files with the appropriate package header in an appropriately-named directory. The source code files should comprise the hw04.src package, and your solution code files, the hw04.sol package. Begin by copying the source code from the course directory to your own personal directory. That is, copy the following files from /course/cs0180/src/hw04/src/*.java to /course/ cs0180/workspace/javaproject/src/hw04/src: ˆ IDictionary.java, containing public interface IDictionary<K,V> ˆ KeyNotFoundException.java, containing public class KeyNotFoundException ˆ KeyAlreadyExistsException.java, containing public class KeyAlreadyExistsException ˆ AbsHashTable.java, containing public abstract class AbsHashTable<K,V>.

2 ˆ IGrep.java, containing public interface IGrep. Do not alter these files! After completing this assignment, the following solution files should be in your /course/cs0180/workspace/javaproject/sol/hw04/sol directory: ˆ DIY Grep Grep.java, containing public class Grep, which implements the interface IGrep. GrepTest.txt, which contains documentation of all of your tests for your Grep class. ˆ Hash Tables Chaining.java, containing public class Chaining<K,V>, which extends AbsHashTable<K,V>. HashTableTester.java containing public class HashTableTester, which tests your hash table implementation. ˆ Hash Table Iterator Iterator.tex, which contains your answers to the Hash Table Iterator question. To hand in your files, navigate to the /course/cs0180/workspace/javaproject/ directory, and run the command cs018 handin hw04. This will automatically hand in all of the above files. Once you have handed in your homework, you should receive an , more or less immediately, confirming that fact. If you don t receive this , try handing in again, or ask the TAs what went wrong. Java s Built-in Hash Tables In this homework, you will be completing an implementation of a chaining hash table. For the problem that does not involve implementing hash tables, 1 you can (and should) make use of one of Java s built-in hash tables, specifically, HashMap or HashSet. These classes differ in that the former uses a hash table to represent a dictionary, 2 while the latter uses a hash table to represent a set. Observe that a set is a special case of a dictionary; the keys are the elements of the set, and there are no values. 3 Consequently, it is straightforward to use a hash table to represent a set. You can use Java s HashMap class by importing java.util.hashmap. Documentation on how to use Java s HashMap can be found here. Likewise, you can use Java s HashSet class by importing java.util.hashset. Documentation on how to use Java s HashSet can be found here. 1 DIY Grep 2 Also called a map; however, we refrain from using this term in CS 18, since it means something entirely different in CS 17/ CS Recall the invariant that dictionaries do not allow duplicate keys. That is why it makes sense to view sets as dictionaries. 2

3 Problems 1 DIY Grep Suppose you want to search a file for a word and retrieve all the line numbers on which that word appears. If you know that you ll have to support lots of queries, you ll probably want to preprocess your file to make it easier to look words up. Task: Explain how you can preprocess a file to make it easy to look up the line numbers associated with each word in the file. Hint: Use a dictionary. Note: Write your answer to this question at the top of the Grep class, which the next task asks you to write. Task: Write a class Grep with a constructor and a single method, lookup. Your constructor should take as input a filename and perform any necessary preprocessing. The lookup method should take as input a word and return the line numbers on which that word appears in the file. It should operate in expected constant time. As noted above, you can (and should) make use of Java s built-in hash table data structure, which is called HashMap, to solve this problem. Notes: ˆ If the same word appears more than once on the same line, you should include the line number only once in your output. ˆ You should treat words as sequences of characters separated by whitespace; so "flow" and "flow!" are distinct words. Also, you can assume words are case sensitive; so "flower" and "Flower" are distinct words. Hints: ˆ As part of the preprocessing step, you may want to use the split method in the String class, which splits up a string into pieces each time it encounters a specific character, and stores those pieces in an array of strings. ˆ You might find the LineNumberReader class, which extends BufferedReader, useful. It has a method getlinenumber that gets the current line number. ˆ The Java syntax to declare a HashMap that maps, for example, from a String to a Set of Integers is new HashMap<String, Set<Integer>>(). Likewise, the syntax to declare a HashSet of Integers is new HashSet<Integer>(). Task: Write a main method for the Grep class. The String[] args should correspond to a file name, and then at least 1 other word to look for, in that order. For example, running java hw04.sol.grep /course/cs018/src/hw04/iliad tree water cats should print something like: 3

4 tree found on lines: 1353 water found on lines: cats is not found Non-DIY Grep What you ve just written is very similar to one of the functions of the UNIX command grep, an extremely powerful and useful tool. You can use grep to search a file for a given pattern, and report where that pattern appears in the file, as follows: grep -n <pattern> <file> The -n is an optional parameter that tells grep that we want it to report line numbers. It prints out each line of text next to the line number. This is but one of many, many grep features, which are fully documented on its man page (which you can access, if you want to learn more, by typing man grep into a terminal). Here s a couple of examples of how you d use grep with this line number option: grep -n polyp myfile This command would print out something like: 1: Lyn likes the word polyp. 4: polyp 9: Lyn needs to stop using the word polyp all the time. Task: Test your Grep class. Document all of your tests in a file called GrepTest.txt. This file should have what you input to your Grep class, what the output was, and a short explanation (a sentence or less) of what you were trying to test with that input. Note: As usual, you should make sure your testing is exhaustive. unexpected program inputs. Test edge cases, and test You cannot easily test your implementation of grep using the Tester library, as you have become accustomed to doing in CS 18. But you can use grep to test your program, simply by comparing the output of your program with the output of grep. Hint: We ve included several test files (thankfully, none of which is the file shown above) in /course /cs018/src/poems/. But do not be afraid to create your own text files for testing, especially to try to catch edge cases! If you do this, make sure to hand in these files with the rest of your code. 2 Chaining Hash Tables In this problem, you will implement a hash table using chaining. Recall that the internal data structure of a hash table implemented using chaining is an array of lists. Although you have built your very own implementation of mutable linked lists by now, we recommend (insist, actually) that you use Java s built-in mutable lists, so that you get some practice using Java s mutable list interface. Java s LinkedList class lives in the java.util library. 4

5 In Java, you cannot create an array of a generic type. In order to circumvent this limitation, you should do the following to create your hash table: this.data = (LinkedList<KVPair<K,V>>[]) new LinkedList[size]; This situation is one of a few exceptions (equals is another) when casting is acceptable; in general, however, it s still discouraged. This line of code will generate a warning that there is an unchecked cast. To get rid of the warning, above any methods that cast like this, you should Typically, warnings such as these indicate a problem with your code, so you should not suppress them; you should pay attention to them! In this specific instance, however, we justify its use as we are trying to get around a Java limitation. Task: Extend AbsHashTable<K,V> with a class Chaining<K, V>. The Chaining constructor should take as input a size variable, which specifies the size of the table. Hint: The key method to write in Chaining is findkvpair. Write this method first, and use it as a helper when you write insert and delete. Task: Test your Chaining class thoroughly. Since your class is generic, be sure to use multiple types in your testing. Additionally, since we are working with a mutable data structure, be sure to have setup methods. Put your tests in the HashTableTester.java file. 3 Hash Table Iterator Note: For this problem, you need not submit any Java code. A high-level description of each algorithm is enough. Whenever you implement a class, you should always override equals, tostring, and hashcode. Whenever you implement a collection, in addition, you should override iterator. We did this successfully for linked lists, and in this problem, you will think about how to do this for hash tables. (You may assume that the hash table does not change while you are iterating; no items are inserted or deleted.) Note: While not part of the assignment, take a moment to think about how you would use an iterator to write equals and tostring for hash tables. First, let s think about how an iterator for a chaining hash table might work. As a first attempt, you could try iterating over all the slots in the hash table: if a slot is empty, you can skip right over it; but if it is not empty, you would then iterate over the bucket stored at that slot. Task: The iterator we just described would examine all n slots in the chaining hash table, even though there might not be data stored at all, or even most, of them. Explain how to implement a more efficient chaining iterator that only examines slots which store data. Your iterator should not affect the run time of the hash table s basic operations; that is, the run times of lookup, insert, update, and delete should not change. 5

6 Hint: Consider augmenting the key-value pairs stored in your dictionary with additional fields. Task: Discuss the trade-offs between the naive iterator we proposed, and your iterator design. Please let us know if you find any mistakes, inconsistencies, or confusing language in this or any other CS18 document by filling out the anonymous feedback form: courses/cs018/feedback. 6

Lecture 17: Implementing HashTables 10:00 AM, Mar 5, 2018

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

Homework 2: Imperative Due: 5:00 PM, Feb 15, 2019

Homework 2: Imperative Due: 5:00 PM, Feb 15, 2019 CS18 Integrated Introduction to Computer Science Fisler Homework 2: Imperative Due: 5:00 PM, Feb 15, 2019 Contents 1 Overview of Generic/Parameterized Types 2 2 Double the Fun with Doubly-Linked Lists

More information

Homework 6: Heaps Due: 5:00 PM, Apr 9, 2018

Homework 6: Heaps Due: 5:00 PM, Apr 9, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Homework 6: Heaps Due: 5:00 PM, Apr 9, 2018 1 Sifting Up and Down 2 2 Text Processing 3 3 Appendix 6 Objectives By the end of this

More information

Homework 5: Fun with Scala Due: 5:00 PM, Mar 16, 2018

Homework 5: Fun with Scala Due: 5:00 PM, Mar 16, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Homework 5: Fun with Scala Due: 5:00 PM, Mar 16, 2018 1 Shopping Cart 2 2 Vote Counting 3 3 Earthquake 4 4 Arrays 5 Objectives By

More information

Homework 1: Classes Due: 5:00 PM, Feb 9, 2018

Homework 1: Classes Due: 5:00 PM, Feb 9, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Homework 1: Classes Due: 5:00 PM, Feb 9, 2018 Contents 1 Shape-ology 2 1.1 Rectangle: Take 1..................................... 3 1.2 Triangle...........................................

More information

Lecture 16: HashTables 10:00 AM, Mar 2, 2018

Lecture 16: HashTables 10:00 AM, Mar 2, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 16: HashTables 10:00 AM, Mar 2, 2018 Contents 1 Speeding up Lookup 1 2 Hashtables 2 2.1 Java HashMaps.......................................

More information

Homework 2: Imperative Due: 5:00 PM, Feb 16, 2018

Homework 2: Imperative Due: 5:00 PM, Feb 16, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Homework 2: Imperative Due: 5:00 PM, Feb 16, 2018 1 Double the Fun with Doubly-Linked Lists 3 2 SeatMap 6 3 Memory Maps for Lists

More information

Lab 9: More Sorting Algorithms 12:00 PM, Mar 21, 2018

Lab 9: More Sorting Algorithms 12:00 PM, Mar 21, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lab 9: More Sorting Algorithms 12:00 PM, Mar 21, 2018 Contents 1 Heapsort 2 2 Quicksort 2 3 Bubble Sort 3 4 Merge Sort 3 5 Mirror Mirror

More information

Lab 5: Java IO 12:00 PM, Feb 21, 2018

Lab 5: Java IO 12:00 PM, Feb 21, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 5: Java IO 12:00 PM, Feb 21, 2018 1 The Java IO Library 1 2 Program Arguments 2 3 Readers, Writers, and Buffers 2 3.1 Buffering

More information

Homework 7: Subsets Due: 11:59 PM, Oct 23, 2018

Homework 7: Subsets Due: 11:59 PM, Oct 23, 2018 CS17 Integrated Introduction to Computer Science Klein Contents Homework 7: Subsets Due: 11:59 PM, Oct 23, 2018 1 Bookends (Practice) 2 2 Subsets 3 3 Subset Sum 4 4 k-subsets 5 5 k-subset Sum 5 Objectives

More information

Lecture 23: Priority Queues 10:00 AM, Mar 19, 2018

Lecture 23: Priority Queues 10:00 AM, Mar 19, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 23: Priority Queues 10:00 AM, Mar 19, 2018 Contents 1 Priority Queues 1 2 Binary Heaps 2 3 Heaps 4 4 Aside: The Ordered Trait 5 5

More information

Homework 3: Recursion Due: 11:59 PM, Sep 25, 2018

Homework 3: Recursion Due: 11:59 PM, Sep 25, 2018 CS17 Integrated Introduction to Computer Science Klein Homework 3: Recursion Due: 11:59 PM, Sep 25, 2018 Contents 1 Factorial 3 2 Fibonacci 4 3 Odds Only 5 4 Increment All 6 5 Frequency 6 6 Sublist 7 6.1

More information

Lecture 8: Iterators and More Mutation

Lecture 8: Iterators and More Mutation Integrated Introduction to Computer Science Fisler, Nelson Contents 1 Traversing Lists 1 2 Motivating Iterators 2 3 Writing an Iterator 3 4 Writing Sum with an Iterator 4 Objectives By the end of this

More information

Lecture 5: Implementing Lists, Version 1

Lecture 5: Implementing Lists, Version 1 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 5: Implementing Lists, Version 1 Contents 1 Implementing Lists 1 2 Methods 2 2.1 isempty...........................................

More information

Lecture 23: Priority Queues, Part 2 10:00 AM, Mar 19, 2018

Lecture 23: Priority Queues, Part 2 10:00 AM, Mar 19, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 23: Priority Queues, Part 2 10:00 AM, Mar 19, 2018 Contents 1 Heap Implementation 1 1.1 Insert............................................

More information

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle Boggle If you are not familiar with the game Boggle, the game is played with 16 dice that have letters on all faces. The dice are randomly deposited into a four-by-four grid so that the players see the

More information

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018 Contents 1 Imperative Programming 1 1.1 Sky High Grades......................................

More information

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

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018 1 Terminology 1 2 Class Hierarchy Diagrams 2 2.1 An Example: Animals...................................

More information

Lecture 12: Dynamic Programming Part 1 10:00 AM, Feb 21, 2018

Lecture 12: Dynamic Programming Part 1 10:00 AM, Feb 21, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 12: Dynamic Programming Part 1 10:00 AM, Feb 21, 2018 Contents 1 Introduction 1 2 Fibonacci 2 Objectives By the end of these notes,

More information

Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017

Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017 Integrated Introduction to Computer Science Hughes Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017 Contents 1 Fun with map (Practice) 2 2 Unfold (Practice) 3 3 Map2 3 4 Fold 4 5 All You

More information

Lecture 7: Lists, Version 2 (with Mutation)

Lecture 7: Lists, Version 2 (with Mutation) Integrated Introduction to Computer Science Fisler Contents 1 The Impact of addfirst on Lists 1 2 The Challenge of Sharing Data Structures 2 2.1 Functional Lists in Memory................................

More information

CS159 - Assignment 2b

CS159 - Assignment 2b CS159 - Assignment 2b Due: Tuesday, Sept. 23 at 2:45pm For the main part of this assignment we will be constructing a number of smoothed versions of a bigram language model and we will be evaluating its

More information

CS61BL Summer 2013 Midterm 2

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

Lab 10: Sockets 12:00 PM, Apr 4, 2018

Lab 10: Sockets 12:00 PM, Apr 4, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lab 10: Sockets 12:00 PM, Apr 4, 2018 Contents 1 The Client-Server Model 1 1.1 Constructing Java Sockets.................................

More information

Lab 8: Introduction to Scala 12:00 PM, Mar 14, 2018

Lab 8: Introduction to Scala 12:00 PM, Mar 14, 2018 CS18 Integrated Introduction to Computer Science Fisler Lab 8: Introduction to Scala 12:00 PM, Mar 14, 2018 Contents 1 Getting Started 1 2 Vals vs Vars 1 3 Team Rocket s Shenanigans 2 4 Lunch Time! 3 5

More information

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018 CS17 Integrated Introduction to Computer Science Klein Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018 Contents 1 Reverse (Practice) 4 2 Main Diagonal (Practice) 5 3 Horizontal Flip 6 4 Vertical Flip

More information

Homework #10 due Monday, April 16, 10:00 PM

Homework #10 due Monday, April 16, 10:00 PM Homework #10 due Monday, April 16, 10:00 PM In this assignment, you will re-implement Dictionary as Map container class using the same data structure. A Map has an associated entry set and that set will

More information

Java HashMap Interview Questions

Java HashMap Interview Questions Java HashMap Interview Questions codespaghetti.com/java-hashmap-interview-questions/ HashMap Java HashMap Interview Questions, Algorithms and Programs. Table of Contents: CHAPTER 1: Java HashMap Interview

More information

CS11 Java. Winter Lecture 8

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

CSCI 200 Lab 3 Using and implementing sets

CSCI 200 Lab 3 Using and implementing sets CSCI 200 Lab 3 Using and implementing sets In this lab, you will write a program that manages a set of workers, using the Worker hierarchy you developed in Lab 2. You will also implement your own version

More information

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 Contents 1 Exceptions and How They Work 1 1.1 Update to the Banking Example.............................

More information

Lecture 4: Inheritence and Abstract Classes

Lecture 4: Inheritence and Abstract Classes Integrated Introduction to Computer Science Fisler, Nelson Contents 1 Abstracting over Common Methods in Different Classes 1 2 Inheritence 2 2.1 Simplifying the Boa/Dillo Classes.............................

More information

CMSC 201 Fall 2016 Homework 6 Functions

CMSC 201 Fall 2016 Homework 6 Functions CMSC 201 Fall 2016 Homework 6 Functions Assignment: Homework 6 Functions Due Date: Wednesday, October 26th, 2016 by 8:59:59 PM Value: 40 points Collaboration: For Homework 6, collaboration is not allowed

More information

CS2110: Software Development Methods. Maps and Sets in Java

CS2110: 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 information

// class variable that gives the path where my text files are public static final String path = "C:\\java\\sampledir\\PS10"

// class variable that gives the path where my text files are public static final String path = C:\\java\\sampledir\\PS10 Problem Set 10 Due: 4:30PM, Friday May 10, 2002 Problem 1. Files and hashing, preliminary question (30%) This problem focuses on the use of the hashcode() method, and touches on the tostring() and equals()

More information

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018 Contents 1 Mutation in the Doghouse 1 1.1 Aside: Access Modifiers..................................

More information

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm) CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, 2017 11:30pm) This assignment focuses on recursive backtracking. Turn in the following files using the link on the course

More information

Hashing as a Dictionary Implementation

Hashing as a Dictionary Implementation Hashing as a Dictionary Implementation Chapter 22 Contents The Efficiency of Hashing The Load Factor The Cost of Open Addressing The Cost of Separate Chaining Rehashing Comparing Schemes for Collision

More information

Lecture 7: Implementing Lists, Version 2

Lecture 7: Implementing Lists, Version 2 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 7: Implementing Lists, Version 2 Contents 1 The Impact of addfirst on Lists 1 2 Mutating List Contents 2 2.1 The Basic List Classes...................................

More information

ABSTRACT DATA TYPES: COLLECTIONS, LISTS, SETS, MAP, QUEUES. Thursday, June 30, 2011

ABSTRACT DATA TYPES: COLLECTIONS, LISTS, SETS, MAP, QUEUES. Thursday, June 30, 2011 1 ABSTRACT DATA TYPES: COLLECTIONS, LISTS, SETS, MAP, QUEUES Lecture 4 CS 2110 Summer 2011 Lists are Iterable 4 for public static void printlist(list strings) { for (int idx = 0; idx < strings.size();

More information

CS 310: Hash Table Collision Resolution

CS 310: Hash Table Collision Resolution CS 310: Hash Table Collision Resolution Chris Kauffman Week 8-1 Logistics Reading Weiss Ch 20: Hash Table Weiss Ch 6.7-8: Maps/Sets Homework HW 1 Due Saturday Discuss HW 2 next week Questions? Schedule

More information

Problem 1: Building the BookCollection application

Problem 1: Building the BookCollection application CSCI 200 Lab 10 Creating and Using Maps In this lab, you will implement a BookCollection application using Java s HashMap class. You ll then create and test your own tree-based map and use it in your BookCollection

More information

Review. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( )

Review. 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 information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

Not overriding equals

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

Announcements. Submit Prelim 2 conflicts by Thursday night A6 is due Nov 7 (tomorrow!)

Announcements. 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 information

Lab 1: Setup 12:00 PM, Sep 10, 2017

Lab 1: Setup 12:00 PM, Sep 10, 2017 CS17 Integrated Introduction to Computer Science Hughes Lab 1: Setup 12:00 PM, Sep 10, 2017 Contents 1 Your friendly lab TAs 1 2 Pair programming 1 3 Welcome to lab 2 4 The file system 2 5 Intro to terminal

More information

(Provisional) Lecture 20: OCaml Fun!

(Provisional) Lecture 20: OCaml Fun! CS17 Integrated Introduction to Computer Science Hughes (Provisional) Lecture 20: OCaml Fun! 10:00 AM, Oct 23, 2017 Contents 1 Dictionaries 1 2 Well-Ordering Proof Practice 3 3 Summary 5 Objectives By

More information

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm)

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm) CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, 2019 11:30pm) This assignment focuses on recursive backtracking. Turn in the following files using the link on the

More information

Homework 5. Due Friday, March 1 at 5:00 PM

Homework 5. Due Friday, March 1 at 5:00 PM WRITTEN PROBLEMS Homework 5 Due Friday, March at 5:00 PM I think we can all agree that junior high is filled with embarrassing and awkward and downright humiliating moments, right? - Lizzie McGuire Handing

More information

Homework # 7 DUE: 11:59pm November 15, 2002 NO EXTENSIONS WILL BE GIVEN

Homework # 7 DUE: 11:59pm November 15, 2002 NO EXTENSIONS WILL BE GIVEN Homework #6 CS 450 - Operating Systems October 21, 2002 Homework # 7 DUE: 11:59pm November 15, 2002 NO EXTENSIONS WILL BE GIVEN 1. Overview In this assignment you will implement that FILES module of OSP.

More information

ASSIGNMENT 5 Objects, Files, and More Garage Management

ASSIGNMENT 5 Objects, Files, and More Garage Management ASSIGNMENT 5 Objects, Files, and More Garage Management COMP-202B, Winter 2010, All Sections Due: Wednesday, April 14, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified,

More information

CS4023 Week06 Lab Exercise

CS4023 Week06 Lab Exercise CS4023 Week06 Lab Exercise Lab Objective: In this week s lab we will look at writing a program that reads a large matrix of numbers and then reports all numbers that are equal to a reference value (or

More information

CSE 143 Au03 Final Exam Page 1 of 15

CSE 143 Au03 Final Exam Page 1 of 15 CSE 143 Au03 Final Exam Page 1 of 15 Reference information about many standard Java classes appears at the end of the test. You might want to tear off those pages to make them easier to refer to while

More information

COSC2430 Hw2: Name list management (Linked lists practice)

COSC2430 Hw2: Name list management (Linked lists practice) COSC2430 Hw2: Name list management (Linked lists practice) 1. Introduction You will create a C++ program to manage a name list. Read a file that has a lot of items that stand for the information of a name

More information

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists COMP-202B, Winter 2009, All Sections Due: Tuesday, April 14, 2009 (23:55) You MUST do this assignment individually and, unless otherwise

More information

CS61B 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: 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 information

Lecture 22: Garbage Collection 10:00 AM, Mar 16, 2018

Lecture 22: Garbage Collection 10:00 AM, Mar 16, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 22: Garbage Collection 10:00 AM, Mar 16, 2018 Contents 1 What is Garbage Collection? 1 1.1 A Concrete Example....................................

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

Lab 7: OCaml 12:00 PM, Oct 22, 2017

Lab 7: OCaml 12:00 PM, Oct 22, 2017 CS17 Integrated Introduction to Computer Science Hughes Lab 7: OCaml 12:00 PM, Oct 22, 2017 Contents 1 Getting Started in OCaml 1 2 Pervasives Library 2 3 OCaml Basics 3 3.1 OCaml Types........................................

More information

Good Coding Practices Spring 2018

Good Coding Practices Spring 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Good Coding Practices Spring 2018 1 Introduction 1 2 The Don ts 1 3 The Dos 4 4 CS 18-Specific Practices 5 5 Style 6 1 Introduction

More information

09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013

09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013 1 TYPE CHECKING AND CASTING Lecture 5 CS2110 Spring 2013 1 Type Checking 2 Java compiler checks to see if your code is legal Today: Explore how this works What is Java doing? Why What will Java do if it

More information

CS/ENGRD 2110 SPRING Lecture 3: Fields, getters and setters, constructors, testing

CS/ENGRD 2110 SPRING Lecture 3: Fields, getters and setters, constructors, testing 1 CS/ENGRD 2110 SPRING 2019 Lecture 3: Fields, getters and setters, constructors, testing http://courses.cs.cornell.edu/cs2110 CS2110 Announcements 2 Take course S/U? OK with us. Check with your advisor/major.

More information

ASSIGNMENT 5 Objects, Files, and a Music Player

ASSIGNMENT 5 Objects, Files, and a Music Player ASSIGNMENT 5 Objects, Files, and a Music Player COMP-202A, Fall 2009, All Sections Due: Thursday, December 3, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified, you

More information

Lecture 23: Priority Queues, Part 2 10:00 AM, Mar 19, 2018

Lecture 23: Priority Queues, Part 2 10:00 AM, Mar 19, 2018 CS8 Integrated Introduction to Computer Science Fisler, Nelson Lecture : Priority Queues, Part : AM, Mar 9, 8 Contents Sorting, Revisited Counting Sort Bucket Sort 4 Radix Sort 6 4. MSD Radix Sort......................................

More information

CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings)

CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings) CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings) Assignment: Homework 4 Lists (and Loops and Strings) Due Date: Friday, March 3rd, 2017 by 8:59:59 PM Value: 40 points Collaboration: For Homework

More information

Lecture 11: In-Place Sorting and Loop Invariants 10:00 AM, Feb 16, 2018

Lecture 11: In-Place Sorting and Loop Invariants 10:00 AM, Feb 16, 2018 Integrated Introduction to Computer Science Fisler, Nelson Lecture 11: In-Place Sorting and Loop Invariants 10:00 AM, Feb 16, 2018 Contents 1 In-Place Sorting 1 2 Swapping Elements in an Array 1 3 Bubble

More information

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too) CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too) HW6 NOTE: Do not use the STL map or STL pair for HW6. (It s okay to use them for the contest.)

More information

Today. Book-keeping. Exceptions. Subscribe to sipb-iap-java-students. Collections. Play with problem set 1

Today. Book-keeping. Exceptions. Subscribe to sipb-iap-java-students.  Collections. Play with problem set 1 Today Book-keeping Exceptions Subscribe to sipb-iap-java-students Collections http://sipb.mit.edu/iap/java/ Play with problem set 1 No class Monday (MLK); happy Hunting Problem set 2 on Tuesday 1 2 So

More information

INSTRUCTIONS TO CANDIDATES

INSTRUCTIONS TO CANDIDATES NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING MIDTERM ASSESSMENT FOR Semester 2 AY2017/2018 CS2030 Programming Methodology II March 2018 Time Allowed 90 Minutes INSTRUCTIONS TO CANDIDATES 1. This

More information

CSCI 355 Lab #2 Spring 2007

CSCI 355 Lab #2 Spring 2007 CSCI 355 Lab #2 Spring 2007 More Java Objectives: 1. To explore several Unix commands for displaying information about processes. 2. To explore some differences between Java and C++. 3. To write Java applications

More information

COMP 250. Lecture 27. hashing. Nov. 10, 2017

COMP 250. Lecture 27. hashing. Nov. 10, 2017 COMP 250 Lecture 27 hashing Nov. 10, 2017 1 RECALL Map keys (type K) values (type V) Each (key, value) pairs is an entry. For each key, there is at most one value. 2 RECALL Special Case keys are unique

More information

CSC 321: Data Structures. Fall 2017

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

Lab 1: Introduction to Java

Lab 1: Introduction to Java Lab 1: Introduction to Java Welcome to the first CS15 lab! In the reading, we went over objects, methods, parameters and how to put all of these things together into Java classes. It's perfectly okay if

More information

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Have the students look at the editor on their computers. Refer to overhead projector as necessary. Intro to Programming (Time 15 minutes) Open the programming tool of your choice: If you ve installed, DrRacket, double-click the application to launch it. If you are using the online-tool, click here to

More information

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved

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

Topic 22 Hash Tables

Topic 22 Hash Tables Topic 22 Hash Tables "hash collision n. [from the techspeak] (var. `hash clash') When used of people, signifies a confusion in associative memory or imagination, especially a persistent one (see thinko).

More information

Scala Style Guide Spring 2018

Scala Style Guide Spring 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Scala Style Guide Spring 2018 Contents 1 Introduction 1 2 Naming 1 3 Formatting 2 4 Class Declarations 3 5 Functional Paradigms 4 6 Comments

More information

CS451 - Assignment 3 Perceptron Learning Algorithm

CS451 - Assignment 3 Perceptron Learning Algorithm CS451 - Assignment 3 Perceptron Learning Algorithm Due: Sunday, September 29 by 11:59pm For this assignment we will be implementing some of the perceptron learning algorithm variations and comparing both

More information

CS2110: Software Development Methods. Maps and Sets in Java

CS2110: 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 information

Project 4 Query Optimization Part 2: Join Optimization

Project 4 Query Optimization Part 2: Join Optimization Project 4 Query Optimization Part 2: Join Optimization 1 Introduction Out: November 7, 2017 During this semester, we have talked a lot about the different components that comprise a DBMS, especially those

More information

Answer Key. 1. General Understanding (10 points) think before you decide.

Answer Key. 1. General Understanding (10 points) think before you decide. Answer Key 1. General Understanding (10 points) Answer the following questions with yes or no. think before you decide. Read the questions carefully and (a) (2 points) Does the interface java.util.sortedset

More information

CS 310: Maps and Sets

CS 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

Chapter 2.6: Testing and running a solution

Chapter 2.6: Testing and running a solution Chapter 2.6: Testing and running a solution 2.6 (a) Types of Programming Errors When programs are being written it is not surprising that mistakes are made, after all they are very complicated. There are

More information

Points off Total off Net Score. CS 314 Final Exam Spring 2017

Points off Total off Net Score. CS 314 Final Exam Spring 2017 Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2017 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.

More information

For this section, we will implement a class with only non-static features, that represents a rectangle

For this section, we will implement a class with only non-static features, that represents a rectangle For this section, we will implement a class with only non-static features, that represents a rectangle 2 As in the last lecture, the class declaration starts by specifying the class name public class Rectangle

More information

11 HashMap: Overriding equals ; JUnit; Vistors

11 HashMap: Overriding equals ; JUnit; Vistors 11 HashMap: Overriding equals ; JUnit; Vistors Goals In this lab we will first learn how to define the equals method, as well as how to use the HashMap data structure defined in the Java Collections Frameworks.

More information

Lecture 27: (PROVISIONAL) Insertion Sort, Selection Sort, and Merge Sort 10:00 AM, Nov 8, 2017

Lecture 27: (PROVISIONAL) Insertion Sort, Selection Sort, and Merge Sort 10:00 AM, Nov 8, 2017 Integrated Introduction to Computer Science Hughes Lecture 27: (PROVISIONAL) Insertion Sort, Selection Sort, and Merge Sort 10:00 AM, Nov 8, 2017 Contents 1 Program Structure and Data Structure 1 2 Sorting

More information

CS 051 Homework Laboratory #2

CS 051 Homework Laboratory #2 CS 051 Homework Laboratory #2 Dirty Laundry Objective: To gain experience using conditionals. The Scenario. One thing many students have to figure out for the first time when they come to college is how

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2005 P. N. Hilfinger Project #2: Static Analyzer for Pyth Due: Wednesday, 6 April

More information

CSCI 355 LAB #2 Spring 2004

CSCI 355 LAB #2 Spring 2004 CSCI 355 LAB #2 Spring 2004 More Java Objectives: 1. To explore several Unix commands for displaying information about processes. 2. To explore some differences between Java and C++. 3. To write Java applications

More information

CpSc 1111 Lab 9 2-D Arrays

CpSc 1111 Lab 9 2-D Arrays CpSc 1111 Lab 9 2-D Arrays Overview This week, you will gain some experience with 2-dimensional arrays, using loops to do the following: initialize a 2-D array with data from an input file print out the

More information

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018 Integrated Introduction to Computer Science Klein Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018 Contents 1 Fun with map (Practice) 2 2 Unfold (Practice) 3 3 Map2 3 4 Fold 4 5 All You

More information

CSCI 200 Lab 4 Evaluating infix arithmetic expressions

CSCI 200 Lab 4 Evaluating infix arithmetic expressions CSCI 200 Lab 4 Evaluating infix arithmetic expressions Please work with your current pair partner on this lab. There will be new pairs for the next lab. Preliminaries In this lab you will use stacks and

More information

STANDARD ADTS Lecture 17 CS2110 Spring 2013

STANDARD ADTS Lecture 17 CS2110 Spring 2013 STANDARD ADTS Lecture 17 CS2110 Spring 2013 Abstract Data Types (ADTs) 2 A method for achieving abstraction for data structures and algorithms ADT = model + operations In Java, an interface corresponds

More information

MIDTERM EXAM THURSDAY MARCH

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

Safety SPL/2010 SPL/20 1

Safety SPL/2010 SPL/20 1 Safety 1 system designing for concurrent execution environments system: collection of objects and their interactions system properties: Safety - nothing bad ever happens Liveness - anything ever happens

More information

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam 1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Exam Name: Email Address: TA: Section: You have three hours to complete this exam. For coding questions, you do not need to include

More information