import java.math.BigInteger; /* 2m Video for details: https://youtu.be/HyrqiAlYBUg { private E[] table1, table2; private int count; private int defaultSize = 7; /* * Grading: * Correctly initializes...

Video description: https://www.youtube.com/watch?v=HyrqiAlYBUgMLA referencing not applicable.


import java.math.BigInteger; /* 2m Video for details: https://youtu.be/HyrqiAlYBUg<----- *="" complete="" the="" a5cuckoo()="" method="" *="" complete="" the="" a5cuckoo(int="" size)="" method="" *="" complete="" the="" insert(e="" val)="" method="" *="" complete="" the="" contains(e="" val)="" method="" *="" complete="" the="" get(e="" val)="" method="" *="" complete="" the="" remove(e="" val)="" method="" *="" complete="" the="" makeempty()="" method="" *="" complete="" the="" hashfortable1(e="" val)="" method="" *="" complete="" the="" hashfortable2(e="" val)="" method="" *="" complete="" the="" rehash()="" method="" */="" public="" class=""> { private E[] table1, table2; private int count; private int defaultSize = 7; /* * Grading: * Correctly initializes all values - 0.5pt */ public A5Cuckoo() { //create tables using defaultSize } /* * Grading: * Correctly initializes all values - 0.5pt */ public A5Cuckoo(int size) { //create tables using prime larger than size } /* * Grading: * Correctly inserts value into available position - 1pt * Correctly moves values 1 step - 1pt * Correctly moves values multiple steps - 2pt * Correctly determines when to rehash - 2pt */ public void insert(E val) { //add item to table1 or table 2 //move other items between table1/table2 if needed //rehash if more than half full or can't complete insert } /* * Grading: * Correctly finds if value exists in table or not - 1pt */ public boolean contains(E val) { //return true/false if the value exists in the structure return false; } /* * Grading: * Correctly returns value from table - 1pt */ public E get(E val) { //return the object if it exists in the structure return null; } /* * Grading: * Correctly removes value from table - 1pt */ public boolean remove(E val) { //return true/false if the value was successfully removed from the structure return false; } /* * Grading: * Correctly empties both tables - 1pt */ public void makeEmpty() { //clear both table1 and table2 of values, maintain current size } /* * Grading: * Correctly finds position for value - 1pt * Uses full universal hashing formula - 1pt */ private int hashForTable1(E val) { //return a valid position in table1 using a form of Universal Hashing (slide 24 from part 3) //ensure the formula for finding a position is different for both return 0; } /* * Grading: * Correctly finds position for value - 1pt * Uses full universal hashing formula - 1pt * Ensure position is different than table1 for the majority of values - 1pt */ private int hashForTable2(E val) { //return a valid position in table2 using a form of Universal Hashing (slide 24 from part 3) //ensure the formula for finding a position is different for both return 0; } /* * Grading: * Correctly creates larger tables of correct sizes - 1pt * Correctly rehashes values to new tables - 1pt */ private void rehash() { //make the tables the prime above double the current size and move values into the new tables } /* * COMPLETED METHODS */ public void testPositions(int n) { System.out.println("Value:Table1:Table2"); for(Integer i = 0; i <= n; i++) { system.out.println(i+":"+hashfortable1((e)i)+":"+hashfortable2((e)i)); } } private int nextprime(int n) { return new biginteger(""+n).nextprobableprime().intvalue(); } public int getusedspace() { return count; } public int getavailablespace() { //total - used = available return table1.length+table2.length-count; } public string tostring() { string output = "table1\n"; if(table1 != null) { for(e val : table1) { if(val != null) output += val+","; } } output += "table2\n"; if(table1 != null) { for(e val : table2) { if(val != null) output += val+","; } } return output; } } n;="" i++)="" {="" system.out.println(i+":"+hashfortable1((e)i)+":"+hashfortable2((e)i));="" }="" }="" private="" int="" nextprime(int="" n)="" {="" return="" new="" biginteger(""+n).nextprobableprime().intvalue();="" }="" public="" int="" getusedspace()="" {="" return="" count;="" }="" public="" int="" getavailablespace()="" {="" total="" -="" used="available" return="" table1.length+table2.length-count;="" }="" public="" string="" tostring()="" {="" string="" output="Table1\n" ;="" if(table1="" !="null)" {="" for(e="" val="" :="" table1)="" {="" if(val="" !="null)" output="" +="val+",";" }="" }="" output="" +="Table2\n" ;="" if(table1="" !="null)" {="" for(e="" val="" :="" table2)="" {="" if(val="" !="null)" output="" +="val+",";" }="" }="" return="" output;="" }="">
Jul 24, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here