Given a set of keys and a hash function, generate by hand a 26 element lookup ta
ID: 3706505 • Letter: G
Question
Given a set of keys and a hash function, generate by hand a 26 element lookup table g, to create a perfect hash. Also create the final data table. The keys are: auto, break, case, const, for, switch, struct, while, static, continue The hash function is: h(key) = ( g(first-letter-of-key] + glast-letter-of-key] + length-of-key ) 96 10 Hint: Although this assignment is a hand execution, not a program implementation, you may still wish to write some code to help you generate and display the indexes programmatically, so that you can check for collisions more easily. You could also use Excel, your choice. Turn in: 1) Paper prjnt out of your look-up table g. similar to that shown below value char 2) Paper diagram of your final data table, similar to that shown below, but with key values. Page 1 of 1Explanation / Answer
h(auto) = (g(a) + g(o) + 4) % 10 = (1 + 15 + 4) % 10 = 0
h(break) = (g(b) + g(k) + 5) % 10 = (2 + 12 + 5) % 10 = 7
h(case) = (g(c) + g(e) + 4) % 10 = (3 + 5 + 4) % 10 = 2
h(const) = (g(c) + g(t) + 5) % 10 = (3 + 20 + 5) % 10 = 8
h(for) = (g(f) + g(r) + 3) % 10 = (6 + 18 + 3) % 10 = 7 (collision)
h(switch) = (g(s) + g(h) + 6) % 10 = (19 + 8 + 6) % 10 = 3
h(struct) = (g(s) + g(t) + 6) % 10 = (19 + 20 + 6) % 10 = 5
h(while) = (g(w) + g(e) + 5) % 10 = (23 + 5 + 5) % 10 = 3 (collision)
h(static) = (g(s) + g(c) + 6) % 10 = (19 + 3 + 6) % 10 = 8 (collision)
h(continue) = (g(c) + g(e) + 8) % 10 = (3 + 5 + 8) % 10 = 6
index key
0
1
2 case
3 switch , while
4
5 struct
6 continue
7 break, for
8 const, static
9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.