Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a simple C++ program which will identify how many collisions occur for eac

ID: 3696139 • Letter: W

Question

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.

Explanation / Answer

/*C++ code which will identify how many collisions occur for each of the numbers from 200 thru 600 */

#include <fstream>
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int array[100];

int j = 0;
cout << " numbers: ";
for (int i = 200; i <= 600 ; i = i + 5)
{
array[j] = i;
cout << array[j] << " ";
j++;
  
}

cout << endl;
  
int size = j;
int divisor = 100;
int count100[100];

for (int i = 0; i < 100; ++i)
{
count100[i] = 0;
}

int index;
for (int i = 0; i < size; ++i)
{
index = array[i]%divisor;
count100[index]++;
}

divisor = 101;
int count101[100];
for (int i = 0; i < 100; ++i)
{
count101[i] = 0;
}

for (int i = 0; i < size; ++i)
{
index = array[i]%divisor;
count101[index]++;
}

cout << " 101 results: ";
for (int i = 0; i < 100; ++i)
{
cout << count101[i] << " ";
}

cout << endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote