Algorithms and OOD (CSC 207 2014S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
Do I have to worry about whitespace characters, such as tabs and newline?
Nope.
Is the empty string the empty string?
Yes.
Can we crash on invalid strings, such as "\"?
Yes.
Do we have to assume that JSON represents an array or string?
I'd prefer that you assume that JSON can represent any type. But if you can find it in the ECMA standard, you can assume it represents only an array or string.
To put an object, put the key value pair at index hash(key) % table-size
this.values[hash(key) % this.values.size] = new KeyValuePair(key,value);
To get an object, get the key/value pair at index hash(key) % table-size
return this.values[hash(key) % this.values.size].value;
Note: We typically put a lot of blank space in the table in order to achieve efficiency.
Letter values
A: 1 F: 6 K: 11 P: 16 U: 21 Z: 26
B: 2 G: 7 L: 12 Q: 17 V: 22
C: 3 H: 8 M: 13 R: 18 W: 23
D: 4 I: 9 N: 14 S: 19 X: 24
E: 5 J: 10 O: 15 T: 20 Y: 25
Hash table
0: 10: 20:
1: 11: 21:
2: erin (32) 12: vasi (42) 22:
3: sam (33) 13: 23:
4: shen (32) 14: 24:
5: 15: 25: helen (25)
6: 16: 26: graeme (26)
7: 17: nora (37) 27:
8: 18: alex (18) 28:
9: 19: 29:
Additional: shen (32), fengyuan (25), madeleine (18)
sam: 19 + 1 + 13 = 33, goes in cell 3
Question: How do you implement get when you use the "rehash" approach?
Question: Is this still constant?
int hashCode()Sample hash function
public class Rational
{
BigInteger numerator;
BitInteger denominator;
public int hashCode()
{
return numerator.hashCode() * 2 + denominator.hashCode() * 3;
} // hashCode()
How do we get rid of sam?
0: 10: 20:
1: 11: 21:
2: erin (32) 12: vasi (42) 22:
3: shen (32) 13: 23:
4: leon (32) 14: 24:
5: 15: 25: helen (25)
6: 16: 26: graeme (26)
7: 17: 27: helena (25)
8: 18: alex (18) 28:
9: 19: 29:
put? If you hit one of these "deleted"
cells, use the cell.Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.