HASHING PROJECT: EXERCISE 5, CHAPTER 12, PAGE 628 book data sturcture and other
ID: 3536713 • Letter: H
Question
HASHING PROJECT: EXERCISE 5, CHAPTER 12, PAGE 628
book data sturcture and other objects using c++
Implement a dictionary program using either one of the tables defined in the chapter code. The program should return a definition, given a word in the dictionary. The simplest hash function for a string called s is probably:
int result = 0;
for(int i = 0; i < s.length(); ++i)
result = result + static_cast<int> (s[i]);
return (result % table_size);
Explanation / Answer
# Works as expected >>> 14/2 7 >>> 10/5 2 >>> 27/3 9 # Now divide some numbers that should result in decimals # Here we would expect 1.5 >>> 3/2 1 # The following should give us 1.4 >>> 7/5 1 # In the following case, we'd expect 2.3333 >>> 14/6 2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.