@w1024020103
2017-04-22T15:11:36.000000Z
字数 537
阅读 537
CS61B
B LEVEL
2.
A LEVEL
这道题跟Lecture 23的slide上一个food for thoughts是一样的:
我认为是因为如果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.
跟上面那道题类似,来自Algorithm 4th edition的说法(base-10 numbers就是十进制数):
2.
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)
后面题目不想做了,看不大懂。