Blame | Last modification | View Log | RSS feed
Ira SnyderCS241 Section 01Project #1: Open HashingDue: 10-22-2004Purpose:The purpose of this project is to implement an open hashing scheme in orderfor us as students to better learn how hashing works. This program will alsohelp by showing us which hashing methods work the best.How I modified the put() method:In order to change the method that put() uses to choose the next position toattempt to insert a key/value pair, I did two things. One, I added a newprivate variable, int probeType, to the HashTable class. This allows me tomake a runtime call to the class to set this variable, which will select theprobing method to use. The second thing I added was a switch statement tothe nextProbe() method which decides which probe method to use based on thevalue in the probeType variable (using a switch statement). Choosing theprobe method this way allows for easy automation of the driver program.I also had to modify the put() method by adding a few print statements inorder to get the desired output.For each run specifically:run0: call HashTable.setProbeType(0), then run normally (Linear Probing)run1: call HashTable.setProbeType(1), then run normally (Prime Probing p=3)run2: call HashTable.setProbeType(2), then run normally (Prime Probing p=5)run3: call HashTable.setProbeType(3), then run normally (Prime Probing p=7)run4: call HashTable.setProbeType(4), then run normally (Prime Probing p=11)run5: call HashTable.setProbeType(5), then run normally (Quadratic Probing)run6: call HashTable.setProbeType(6), then run normally (Double Hashing)Analysis of Output:Best in order of least to most collisions:Prime Probing p=3 8 collisionsQuadratic Probing 8 collisionsDouble Hashing 9 collisionsPrime Probing p=7 11 collisionsLinear Probing 14 collisionsPrime Probing p=5 21 collisionsPrime Probing p=11 23 collisionsSo, in terms of least collisions, Prime Probing p=3 and Quadratic Probing arethe best, and Prime Probing p=11 is the worst. However, analyzing theprintouts of where the values were inserted leads me to a differentconclusion. Based on the printouts, I believe that Quadratic Probing is thebest because it seems to work very well even when the load gets very high.This is also true of Double Hashing. I think the result of Prime Probing p=3performing very well is a consequence of the data set used. If many differentdata sets were used, I believe that Quadratic Probing and Double Hashing wouldshow up as the best general probing methods (best in the majority of cases).