This assignment lets you visually experience the decreasing performance of a
hashtable the more it is filled. Your task: build a hashtable, size = 100
elements, and visualize it in the following way (at least similar):

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:
int r =
(int)255/7*coll; // coll = 0: r = 0. coll >=7: r>=255.
r = (int)Math.min(r,255);// same as: if (r>255) r = 255;
int g = 255-r; // green value: the 'opposite' of r: if r=255=> g=0 and vice
versa.
int b = 0; // sets blue to zero, only red/green values are displayed
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.
GUI: the boxes
can either be drawn using custom drawing, or you can just fill a grid with
panels and set the background color. I would do custom drawing (MUCH more
efficient), but that's just me.
That's it!
Due date: best
before Thursday, December 8, 2010 23:59:59 THERE IS NO 2 WEEK 6 POINT DEADLINE FOR
THIS ASSIGNMENT, SINCE Dec.8 is the start of your STUDY DAYS. It's all or
nothing... 1 week.