Computer Science 112 Spring 2015
Gregory M. Kapfhammer
Introduction to Computer Science II
Keep in touch!

Office Hours, Email, Web, Twitter

Key Value Pairs
Counting Word Frequencies
git pull
Run with Ant
build.xml file
Try different inputs
Common words in Java
Common words in English
Use your own files as input
Project Gutenberg
Add Debugging Output?
A word that is already being tracked
A new word not previously tracked
Review design trade-offs
Hashing Functions
Goal: convert and object into a number
Let's start with strings
Java's default implementation
git pull
Compile and run the HashCodeDemonstration
What is the output?
Add in some other data types
Can you produce a collision?
Okay, let's build our own!
Just sum the values of the characters
Strengths and weaknesses?
Can you produce a collision?
Well, let's try another approach!
Sum the characters and multiply by prime numbers
Is this better or worse?
Shift the bits inside of the string
See page 413 for details
Use bitwise shift operators
See table 10.1 on page 414
What is a good shift value?
Can you explain why?
So, now we have numbers. Is this enough?
No! They need to fit into the size of the array!
We need to use a compression function!
We want to avoid collisions!
Try the division method
Try the multiply and divide method
git pull
See page 416 for details
Do DIV and MAD produce correct values?
Do DIV and MAD produce the same values?
Which produces more collision?
Prime vs. Non-prime for N
Prime number pages
Visual inspection is hard
How can we automatically track?
Implement your own solution
Answers to all of the questions?
What do we do when a collision occurs?
Separate Chaining
See page 417