Definition of a Hash Table Hosh tables aro good for doing a quick search on things. For instance It we have an array tull of data (say 100 items). if we knew the position that a specific item is stored in an array, then we could quickly access it. For instance, we just happen to know that the item we want it is at position 3, We can apply myitem=myaray|3]: With this, we don't have to search through aach element in the array, we just access position 3. The queation is, hew do we know that pasition 3 stores the data that we are nterested in? This is where hashing comes in handy.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Definition of a Hash Table
Hash tables aro good for doinga quick
search on things.
For instance if we have an array tuli of
data (say 100 items). If we knew the
pasition that a specific item is stored in
an array, then we could quickly access it.
For instance, we just happen to know that
the item we want it is at position 3, We
can apply.
myitem=myaray[3]:
With this, we don't have to search through
sach element in the array, we just access
position 3.
The question is, how do we know that
pasition 3 stores the data that we gre
interested in?
This is where hashing comes in handy.
Given some key. we can apply o hash
function to it to find an index or position
that we wont to acces.
What is the hash function?
There are many different hosh functions.
Some hash funotions will take an integer
key and turn it into an index. A common
one is the dlivision method.
Let's learn through an example
Divislon method (one hash
method for integers)
Let's say you hod the following numbers
or keys that you wanted to mop into an
cirray of 10 elements:
123458
123467
123450
To apply the division methad, you couldi
divide the number by 10 (or the maximum
number of elements in the array) and use
the remainder (the modulo) as an index
The fallowing would result:
123456 % 10 = 6 (the remainder is 6 when
dividing by 10)
123467 X 10 = 7 (the remainder is 7)
123450 % 10 = 0 (the remainder is 0)
These numbers would be inserted into
the array at positions 6, 7, and 0
respectively.
A problem occurs when two keys yield
the same Index. For Instance, say we
wanted to include:
123467 X 10 = 7 (the remainder is 7)
123457 % 10 = 7 (the remainder is 7)
We have a collision becauso 123467s is
already stored at array index 7.
We need a method to resolve this using
Linear Probing : We search sequentially
for the next empty location
You have to write a code to create
a Hash table to store student ids
188262
182105
187795
197709
198219
186623
195409
190738
189797
186653
,use as Hashing function
account Id%table size. Define
function that will resolve collision
(LUnear ).
Transcribed Image Text:Definition of a Hash Table Hash tables aro good for doinga quick search on things. For instance if we have an array tuli of data (say 100 items). If we knew the pasition that a specific item is stored in an array, then we could quickly access it. For instance, we just happen to know that the item we want it is at position 3, We can apply. myitem=myaray[3]: With this, we don't have to search through sach element in the array, we just access position 3. The question is, how do we know that pasition 3 stores the data that we gre interested in? This is where hashing comes in handy. Given some key. we can apply o hash function to it to find an index or position that we wont to acces. What is the hash function? There are many different hosh functions. Some hash funotions will take an integer key and turn it into an index. A common one is the dlivision method. Let's learn through an example Divislon method (one hash method for integers) Let's say you hod the following numbers or keys that you wanted to mop into an cirray of 10 elements: 123458 123467 123450 To apply the division methad, you couldi divide the number by 10 (or the maximum number of elements in the array) and use the remainder (the modulo) as an index The fallowing would result: 123456 % 10 = 6 (the remainder is 6 when dividing by 10) 123467 X 10 = 7 (the remainder is 7) 123450 % 10 = 0 (the remainder is 0) These numbers would be inserted into the array at positions 6, 7, and 0 respectively. A problem occurs when two keys yield the same Index. For Instance, say we wanted to include: 123467 X 10 = 7 (the remainder is 7) 123457 % 10 = 7 (the remainder is 7) We have a collision becauso 123467s is already stored at array index 7. We need a method to resolve this using Linear Probing : We search sequentially for the next empty location You have to write a code to create a Hash table to store student ids 188262 182105 187795 197709 198219 186623 195409 190738 189797 186653 ,use as Hashing function account Id%table size. Define function that will resolve collision (LUnear ).
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY