Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program, that would imitate the functionality of the hashmap. In a hashmap there is a concept of key and value. You can

Write a C program, that would imitate the functionality of the hashmap. In a hashmap there is a concept of key and value.

You can assume hashmap as an array, where the array index is the key and the content of the array at that index is value.

If you consider an array of strings, then for every possible string, there is a unique position in that array. How you determine the position of any string, depends on the hash function you design.

After a sequence of input strings, you need to show:

The content of the hashmap array.

Sequence of strings you provided as input.

How many valid elements in hashmap array vs how many inputs you provided.

Example: Say for example, you have an string array (hash_array) of size 100. Now for any string, you can find the key/index value using the following simple function:

int getKey(char *str)

{

index = (sum of ascii values of all the characters in that string )%100.

Return index.

}

Your job would be something like the following:

main()

{

while(input is not equal to stop)

{

key = getKey(input);

hash_array[key] = input;

}

Print hash_array

Print inputs

Print number of valid strings in hash_array

Print total number of inputs }

Note that, the above examples have been shown in a pseudocode manner. You need to implement the main and the getKey function in C.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions