-->
当前位置:首页 > 题库

PROGRAMMING:Chain address hash of average search length

Luz5年前 (2021-05-10)题库379
For the integer array with the specified length of N, it is stored in the hash table with the specified length of M (the hash function used is modulo-M operation). If the chain address method is used to deal with the conflict (here, it means that if the location is the same, it is stored in the same location), the program calculates the average search length when the search is successful and the average search length when the search fails.
###Input example:
The first line contains two integers, representing the number of elements to be stored n, the length of the hash table to be stored (the number of hash function modulo division is also it), and the second line contains n integers separated by spaces.
```in
9 11
47 7 29 11 16 92 22 8 3
```
###Output example:
Output the average length of successful search and the average length of failed search in two lines.
Note: Please express it in the form of total search length divided by total search times (for example: there are 10 successful searches, a total of 30, and the average successful search length is 30 / 10).
```out
12/9
20/11
```






answer:If there is no answer, please comment