Use the hashing formula to calculate the hash of all the following strings. Use the Python Shell (the bottom area of Thonny) to help you calculate these numbers, since they get very large, very fast!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Use the hashing formula to calculate the hash of all the following strings. Use the Python Shell (the
bottom area of Thonny) to help you calculate these numbers, since they get very large, very fast!
A with a base of (11) and a hash size of (100):
AB with a base of 11 and a hash size of 100:
ABC with a base of 11 and a hash size of 100:
ABC with a base of 33 and a hash size of 10000:
Hello with a base of 31 and a hash size of 1000000000
Transcribed Image Text:Use the hashing formula to calculate the hash of all the following strings. Use the Python Shell (the bottom area of Thonny) to help you calculate these numbers, since they get very large, very fast! A with a base of (11) and a hash size of (100): AB with a base of 11 and a hash size of 100: ABC with a base of 11 and a hash size of 100: ABC with a base of 33 and a hash size of 10000: Hello with a base of 31 and a hash size of 1000000000
Let's apply this formula to the "CAT" values ([67, 65, 84]) from earlier:
The first (0) element is 67:
=(0+31)**67
=8341295116763783101242214530037512645920899177987598203537434247253767513206111213488516390334626911
The second (1) element is 65:
=(1+31)**65
68351585149469122636640694597425667667286544715412888638305331450311031224980497600734786781970432
The third (2) element is 84:
=(2+31)**84
35906324357811432983835510485410216480190897616731123104932324864582947382402655361077065845208720508790429280946504247030088321
Are you seeing how ridiculous big those numbers are? With just a few simple calculations, we're hitting 126 digit numbers! It's gonna get even crazier next,
because now we have to add all those numbers together. In this case, we end up with:
Total Sum 35906324357811432983835510493819863182104149840609978329567263178171133105105666453252805423912799053221520992035755424146685664
Now, the whole goal was to have a short and sweet number. That's where our hash_size parameter comes in. We use modulo to cut it down to a fixed size, say
10**9 (one billion):
=
Total Sum % (10**9)
146685664
That number right there is our hashed value. If we modified the original string even just a little, we'd end up with a wildly different value. And because we're
modulo-ing, we keep things pretty small in the end.
Hashing is powerful, but a little tricky. It's fine if you don't understand it perfectly yet, you'll have plenty of time in the future to understand it better. But for
now, you need to be able to do it by hand!
Transcribed Image Text:Let's apply this formula to the "CAT" values ([67, 65, 84]) from earlier: The first (0) element is 67: =(0+31)**67 =8341295116763783101242214530037512645920899177987598203537434247253767513206111213488516390334626911 The second (1) element is 65: =(1+31)**65 68351585149469122636640694597425667667286544715412888638305331450311031224980497600734786781970432 The third (2) element is 84: =(2+31)**84 35906324357811432983835510485410216480190897616731123104932324864582947382402655361077065845208720508790429280946504247030088321 Are you seeing how ridiculous big those numbers are? With just a few simple calculations, we're hitting 126 digit numbers! It's gonna get even crazier next, because now we have to add all those numbers together. In this case, we end up with: Total Sum 35906324357811432983835510493819863182104149840609978329567263178171133105105666453252805423912799053221520992035755424146685664 Now, the whole goal was to have a short and sweet number. That's where our hash_size parameter comes in. We use modulo to cut it down to a fixed size, say 10**9 (one billion): = Total Sum % (10**9) 146685664 That number right there is our hashed value. If we modified the original string even just a little, we'd end up with a wildly different value. And because we're modulo-ing, we keep things pretty small in the end. Hashing is powerful, but a little tricky. It's fine if you don't understand it perfectly yet, you'll have plenty of time in the future to understand it better. But for now, you need to be able to do it by hand!
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

It says every answer is wrong, I am still unsure how to solve the problems. 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education