anonymous
  • anonymous
In Lecture 8, we are shown a hashing implementation (2nd one) which has trick for converting ch to ints. A loop (for c in str) has: val = val + shift*ord(c) shift +=1 I understand the ord() part, I'm just wondering why a multiplier (shift) is applied as well before adding to the val sum? Why not just use ord(c)?
MIT 6.00 Intro Computer Science (OCW)
jamiebookeater
  • jamiebookeater
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
I can only guess that the shift is there to ensure that converting different strings produces different values. (I assume we don't want to end up with fake positive results when searching for certain strings) But I don't know how exactly the shift is solving the problem and Guttag really did not elaborate on that...
anonymous
  • anonymous
That was my guess, too, but I don't see a guarantee of uniqueness there.

Looking for something else?

Not the answer you are looking for? Search for more explanations.