Given an ordered sequence, you are required to create an open-addressed Hash table, then do searching on
Question:
Given an ordered sequence, you are required to create an open-addressed Hash table, then do searching on it. We search for some numbers in it. Some may be found(success), and some maybe not be found(unsuccess). You are required to determine Average Searching Length(ASL) for success searching and unsuccess searching based on the searching results: ASLsucc and ASLunsuc。 The data set maybe is as big as 10000. First, you should input the data into an array and determine the input data number(n), take alpha(α load factor)as 0.8, then get len=n/α. Take the smallest prime number which is greater than len as the length(m) of the hash table. Hash Function set as follows: Hash(key)=key % m; We use linear probing to overcome collision: hask(key, i) = [hash(key) + i ] % m where i=0~1-m.
Input
The first line enters several positive numbers (in ascending order), ending with -1. The second line enters several search numbers ended with -1.
Output
output two doubles in one line with 2 fraction points separated by one space. The first one is ASLsucc, the second one is ASLunsucc.
Examples
input
18 13 36 15 42 10 3 5 9 12 8 28 21 25 30 31 45 23 19 11 -1
16 11 15 30 31 28 41 39 32 -1
output
2.20 3.75
input
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 -1
1 2 13 22 28 30 -1
output
1.00 1.00
Database Systems A Practical Approach to Design Implementation and Management
ISBN: 978-0132943260
6th Edition Global
Authors: Thomas Connolly, Carolyn Begg