[关闭]
@w1024020103 2017-04-22T15:11:36.000000Z 字数 537 阅读 537

Hashing Study Guide

CS61B


B LEVEL

2.1.jpg-144.2kB

A LEVEL

2.JPG-31.4kB

这道题跟Lecture 23的slide上一个food for thoughts是一样的:

23.JPG-109kB

我认为是因为如果M是31的倍数,那么hashCode最后取模都相当于最后一个Sn-1取模,这里的话就是String的最后一个字母相等的话,这些items都要挤到一个bucket里,就会发生collision,这不是好的hashCode.

参考:
Why use a prime number in hashCode?
[Why does Java's hashCode() in String use 31 as a multiplier?](Why does Java's hashCode() in String use 31 as a multiplier?)

1.

3.jpg-76.9kB

跟上面那道题类似,来自Algorithm 4th edition的说法(base-10 numbers就是十进制数):
4.JPG-104.7kB

2.
5.jpg-31.5kB

5.jpg-71.1kB

3.Find 2 strings in Java that hash to the same value (writing code is probably best).
FB 2236
Ea 2236

4.CS61B Fall 2009 midterm, #4 (really beautiful problem)
6.JPG-81kB
7.JPG-34.5kB

后面题目不想做了,看不大懂。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注