Need help w/linear probe method resolving collisions hash

Hi,
I need help with hashing using linear probe method resolving collisions. I cannot for the life of me, figure out how hashing works and what is mean by resolving the collisions. This is an assignment I have, but cannot figure out what I need to do. I've searched everywhere I can think of on the net, but they are all sort of different and still too technical for me to understand hashing and coding it, etc.
So I think the values in the array would be the "Key" to the hash. But what would the "Hash" be that I would need to output in the table column? And what is meant by 20 positions? Can someone help me with the first section, this:
1
2
3
4
5
6
7
8
9
10
cout << "table with 20 positions" << endl;
	cout << "key\thash\tindex\toffset" << endl;
	for (i = 0; i < 15; i++)
	{
		// print array value, hash value, hash value mod table size, hash value divided by table size
		cout << /* array value */ << '\t'
		     << /* hash value */ << '\t'
		     << /* hash value mod table size */ << '\t'
		     << /* hash value / table size */ << endl;
	}


This is the complete code that was given with the assignment. I eventually need to do rehashing, quadratic, and chaining methods as well to resolving collisions, but if I understand what and how resolving collisions works, maybe I can do those myself.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  #include <iostream>

using namespace std;

class hInt
{
public:
	unsigned int operator() (int item) const
	{
		unsigned int value = (unsigned int) item;
		value *= value;		// square the item;
		value /= 256;		// discard the low order 8 bits
		return value % 65536;	// return item in range 0 to 65535;
	}

};

void main()
{
	// declare array with all the values
	int arr[] = {47, 89, 90, 126, 140, 145, 153, 177, 285, 393, 395, 467, 566, 601, 735}, i;
	hInt key;

	cout << "table with 20 positions" << endl;
	cout << "key\thash\tindex\toffset" << endl;
	for (i = 0; i < 15; i++)
	{
		// print array value, hash value, hash value mod table size, hash value divided by table size
		cout << /* array value */ << '\t'
		     << /* hash value */ << '\t'
		     << /* hash value mod table size */ << '\t'
		     << /* hash value / table size */ << endl;
	}

	cout << "table with 10 positions" << endl;
	cout << "key\thash\tindex" << endl;
	for (i = 0; i < 15; i++)
	{
		// print array value, hash value, hash value mod table size
		cout << /* array value */ << '\t'
		     << /* hash value */ << '\t'
		     << /* hash value mod table size */ << endl;
	}
}



Thank you so much!
Topic archived. No new replies allowed.