Question

Write a simple C++ program which will identify how many collisions occur for each of the...

Write a simple C++ program which will identify how many collisions occur for each of the numbers from 200 thru 600, incremented by 5, when mapping to a hash table array of 100 entries.

Do this by creating a variable and looping to force it to have all values: 200, 205, 210… 600.

First use 100 as the divisor and use the modulo function to do mapping. Then use 101 as the divisor with the modulo function to do the mapping.

Separately, set up an array of 100 entries, whose values will be a count of the number of times its index is created. Initialize to zero.

For example: 200 maps to index value ‘i’ = 99. Add 1 to Array[99].

Output the 101 results to see how the distribution would occur.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:-

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main(){
   int num=200;
   int hash[100]={0};
int divisor1=100;
int divisor2=101;
   for(num=200;num<=600;num=num+5){
       hash[num%divisor1]++;
       hash[num%divisor2]++;

   }

   for(int i=0;i<100;i++){
       cout<<"index "<<i<<":"<<hash[i]<<endl;
   }
   return 0;
}

First create a array of 100 elements and initialise to 0.Lets two divisors be divisor1=100 and divisor2=101 and iterate from 200 to 600 by incrementing by 5 ,increase the count of hash array i.e for storing how many time it had mapped.

output of code:-

Add a comment
Know the answer?
Add Answer to:
Write a simple C++ program which will identify how many collisions occur for each of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please complete the following task: Create a C++ hash table program for generating a hash from a string. Create a hash f...

    Please complete the following task: Create a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...

  • I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash funct...

    I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...

  • I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash funct...

    I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...

  • Please Answer the following: 4. 5. >> How long would each of these operations take in...

    Please Answer the following: 4. 5. >> How long would each of these operations take in Big O notation? 4.5 Printing the value of each element in an array. 4.6 Doubling the value of each element in an array. 4.7 Doubling the value of just the first element in an array. 4.8 Creating a multiplication table with all the elements in the array. So if your array is [2, 3,7, 8, 10], you first multiply every element by 2, then...

  • Write a program in C that creates an array of 100 random numbers from 0-99. The...

    Write a program in C that creates an array of 100 random numbers from 0-99. The program sums the random numbers and prints the sum.  It then writes the numbers to a new file using open, close and write. Then looks in the current directory for files that match the pattern “numbers.XXXX”. For each file, open the file and read the file. You can assume that the file will contain 100 integers. Sum the integers. Print the filename and the sum...

  • C Program Question: Write a program that reads all integers that are in the range of...

    C Program Question: Write a program that reads all integers that are in the range of 0 to 100, inclusive from an input file named: a.txt and counts how many occurrences of each are in the file. After all input has been processed, display all the values with the number of occurrences that were in are in the input file. Note: The program ignores any number less than 0 or greater than 100. Note: Do not display zero if a...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and...

    PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and use the multiplication method to generate hash keys. You may use your own linked list code from a previous assignment or you can use a standard sequence container. Partial definitions for the hash table class and a generic data class are provided (C++ and Java versions). You may use them as a starting point if you wish. If you choose to design your own...

  • Java using data structures The objective is to create your own Hash Table class to hold...

    Java using data structures The objective is to create your own Hash Table class to hold a list of employees and their ID numbers. I've provided the TableEntry class which will be each data object in the hash table. The list of employees will be provided as a .txt file and must be read with the code. please create a .txt file called Employees.txt with the info provided so that the java code can read it in. Employees.txt: (No WhiteSpace...

  • Using C++ Language This is your last assignment for this course! It is about 3D vectors...

    Using C++ Language This is your last assignment for this course! It is about 3D vectors and arrays. You can either choose to work with vectors or arrays. You don't need to do both (but, you can!). I am going to describe it using the word array. You can translate it for vectors. The dimensions of the array are 200x600x3. The datatype of the values stored in the array are unsigned char (ranges from 0 to 255). The first dimension...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT