THIS IS A 2 WEEK ASSIGNMENT!
This assignment lets you visually experience the decreasing performance of a hashtable the more it is filled. Build a hashtable consisting of 100 elements, and visualize it in the following way:
The upper part shows little boxes in black, red and green. This is the visualization of each cell of your hashtable. The color of the box corresponds to the number of collisions that occured to the element in the cell. Example: an empty cell should be black, a cell with an element that didn't collide at all should be shown in green.
Use the following color scheme for the cells:
Each color consists of r(red), g(green) and b(blue) values (look into the java.awt.Graphics API how to set a color), determined by the rule:
r = (int)255/7*coll;
r = (int)Math.min(r,255);
g = 255-r;
b = 0;
set r=g=b=0 for an empty cell.'coll' is the number of collisions. Please set coll to '7' if coll>7.
Explanation of the color scheme:
0 collisions will be green, >=7 collision will be red, everything in between will be between red and green, which is yellowish. The number 7 is chosen because it's about log(100). This means that red elements would have performed better in a balanced binary search tree.
The other elements of the GUI:
RESET resets the system (empties the array).
NEXT10 creates 10 random numbers and puts them into the hashtable.
(av. collisions) is a textfield showing the average collisions occured (=total collisions/number of elements in table)
Specifications for the hashtable:
The random numbers should be in a range between [0..1000], use v = Math.random()*1000.
The hash function is H(v)=round(v). The index is H(v)%100.
For collision handling use linear probing.
...and of course you can fill a max. of 100 elements into an array of size 100.
That's it. Enjoy !