Question
LINUX C programming Please make sure the output is correct Please do read data from file, the example below is just a example Third: Hash
LINUX C programming
Please make sure the output is correct
Please do read data from file, the example below is just a example
Third: Hash table (20 points)
In this part, you will implement a hash table containing integers. The hash table has 10,000 buckets. An important part of a hash table is collision resolution. In this assignment, we want you to use chaining with a linked list to handle a collision. This means that if there is a collision at a particular bucket then you will maintain a linked list of all values stored at that bucket. For more information about chaining, see http://research.cs.vt.edu/AVresearch/hashing/openhash.php.
A hash table can be implemented in many ways in C. You must find a simple way to implement a hash table structure where you have easy access to the buckets through the hash function. As a reminder, a hash table is a structure that has a number of buckets for elements to hash into. You will determine where the element falls in the table using the hash function.
You must not do a linear search of the 10,000 element array. We will not award any credit for O(n) time implementation of searches or insertions in the common case.
For this problem, you have to use following hash function: key modulo the number of buckets.
Input format: This program takes a file name as argument from the command line. The file contains successive lines of input. Each line contains a character, either i or s, followed by a tab and then an integer. For each line that starts with i, your program should insert that number in the hash table if it is not present. If the line starts with a s, your program should search the hash table for that value.
Output format: Your program my print two counts: (1) the number of insertions where collision occurred, and (2) the number of successful searches. In the first line your program should print the number of collisions, i.e. during insertion if the bucket already had some data (may not be the same value) then you need to count that as one collision. In the next line, your program should print the number of searches where the value was present in the hash table. You can assume that the program inputs will have proper structure.
Example Execution:
Lets assume we have a text file with the following contents:
file2.txt:
i 10
i 12
s 10
i 10010
s 5
s 10010
The the results will be:
$./third file2.txt
1
2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started