Bonus Project3

advertisement
CSCI 2320 Data Structure Bonus Project 3
Hash Tables with Quadratic probing and Double Hashing
Executive Summary:
A hash table is a data structure that uses a hash function to efficiently map
certain identifiers or keys (e.g., person names) to associated values (e.g., their telephone
numbers). The hash function is used to transform the key into the index (the hash) of an
array element (the slot or bucket) where the corresponding value is to be sought.
You are asked to use quadratic probing and double hashing to implement the hash
function with a given action file.
Project Objective: in completing this project, you will
 Enhance your ability to hash tables
 Familiar with different probing approaches
 Enable yourself to perform the analysis of different hash function with the same
given array size
Due Dates and Honor:
This project will be due by the beginning of the class on Thursday Nov/30/2010.
This is an independent programming project, and it is very important that you understand
and abide by the policy concerning programming projects. Remember, your personal
honor and integrity is far more important than your grade on the project.
Detailed Specification:
1. Download the action file and read the file in your program. Each row
represents one number. If the number does not appear in the hash table, it
means “store number”. If the number exists in the hash table, it means “delete
number”
2. Create an empty array with size variable m
3. Write a quadratic probing function (h(k, i ) = (h(k) + c1*i + c2*i^2) mod m)
with function parameter m for hash function (h(k) = k mod m) and c1 and c2
changeable.
4. Write a double hashing function (h(k, i ) = (h1(k) + ih2(k)) mod m) with
function parameter m1 for hash function (h1(k) = k mod m1) and m2 for hash
function (h2(k) = k mod m2) changeable.
5. Write a hash table print out function, which generates all executed records.
(used for 1st file only) The table generated by the program should looks like:
Action
Store 8
Store 20
…
0
8
8
1
2
3
4
20
5
6
7
#probe
1
After you finished all functions, following are the things you need to carry out:
For file 1:
1.1. Use quadratic probing approach to deal with the action file, while m=8,
c1=1, c2=0. Print out the entire hash table through your print function.
1.2. Use quadratic probing approach to deal with the action file, while m=8,
c1=0, c2=1. Print out the entire hash table through your print function.
1.3. Use quadratic probing approach to deal with the action file, while m=8,
c1=1, c2=2. Print out the entire hash table through your print function.
1.4. Use double hashing approach to deal with the action file, while m1=8,
m2=3. Print out the entire hash table through your print function.
For file 2:
2.1. Use quadratic probing approach to deal with the action file, while m=211,
c1=1, c2=0. Record the total probe# and calculate the average probe#.
2.2. Use quadratic probing approach to deal with the action file, while m=211,
c1=0, c2=1. Record the total probe# and calculate the average probe#.
2.3. Use quadratic probing approach to deal with the action file, while m=211,
c1=1, c2=2. Record the total probe# and calculate the average probe#.
2.4. Use double hashing approach to deal with the action file, while m1=211,
m2=113. Record the total probe# and calculate the average probe#.
2.5. Use double hashing approach to play with your hash function, find your own
(best) m1 and m2 which generates lower average probe# than (2.4). Report your
m1 and m2.
What to Submit:
 A print out results of your program (specify with approach name and parameters)
 Source code of your program.
Download