Find Us On:

# Data Structures - AVL Trees, Hashing

quest5178467

Please help with just the programming section of the assigned homework. All required files are included. Attachments Tags Clarifications

## Data Structures - AVL Trees, Hashing Problem Set 3

mariobeka

This is the solution of the theoretical part, together with the programming
part including the extra credit part.
Attachments
PS3_DataStructures.zip (7 K)
Preview
the key to be searched for * @return the value associated to this key */ @Override public V get(K key) { AvlNode<Pair<K, V>> found = find(new Pair<K, V>(key, null), root); if (found == null) { return null; } return found.element.value; } /** * Internal method to find an item in

Preview
subtree in sorted order. * @param t the node that roots the tree. */ private void printTree( AvlNode<AnyType> t ) { if( t != null ) { printTree( t.left ); System.out.println( t.element ); printTree( t.right ); } } /** * Return the height of node t, or -1, if null.

Preview
null) { lineNr++; StringTokenizer st = new StringTokenizer(str, " ,.-"); // process each word wrt the map while (st.hasMoreTokens()) { String word = st.nextToken(); list = new LinkedList<>(); if (getIndex(word)!=null) list = getIndex(word); list.add(lineNr); map.put(word,list); } } // Close the stream. input.close(); // Print out

Preview
interface Map<K, V> {

Preview
implements Comparable<Pair<K,?>>{ public K key; public V value; public Pair(K theKey,

Preview
1989 mod 10 = 9 [h2(1989) = 1 + 1989 mod 9 = 1] -> (1+1) mod 10 = 2 0 -> 6173 1 —> 4171 2 -> 1989 3 -> 1323 4 -> 4344 5 -> 6 -> 9676 7 -> 8 -> 9 -> 4199 1.4 A simple way

Preview
X

Preview
line : lines) { words = newMap.get(line); if(words == null ) { words = new LinkedList<>(); newMap.put(line, words); } words.add(word); } } return newMap; } public static void main(String[] args) throws IOException { //End the program if no text file name was provided //in the args if (args.length != 1)

Preview
index int homePosition = key.hashCode() % size; // insert into linked list hashTable.get(homePosition).add((new Pair<K, V>(key, value))); // increment number of entries counter++; // check load factor checkForRehashing(); } //exist before then override value else { hashTable.get(positionInfo[0]).get(positionInfo[1]).value = value; } } /** * Get the value out of a pair into

Screenshots