Algorithms and OOD (CSC 207 2014S) : EBoards

CSC207.01 2014S, Class 42: Implementing Dictionaries with Hash Tables


Overview

Preliminaries

Upcoming Work

Admin

Extra Credit

Questions

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.

An introduction to hash tables

Hash function

An exercise

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

Handling collisions

Question: How do you implement get when you use the "rehash" approach?

Question: Is this still constant?

Hashing in Java

Handling removal

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:

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

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.