Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

DATA STRUCTURE IN JAVA (Homework) (about 85% OK)

Monkey
Monkey 


Implement and test the following problems: C-10.37 page 454 C-10.38 page 454 ============================= Please let me know if you can help me as soon as possible. Thank you so much. ============================= I will also agree with result of this assignment that will only complete about 85%. Attachments Tags
Clarifications

Answers

DATA STRUCTURE IN JAVA - Solution

mariobeka
mariobeka 



Implement and tested problems:
C-10.36 page 454
C-10.37 page 454
C-10.38 page 454
Attachments
Solution.zip (9 K) Download
Preview
nearby prime) return answer; } // private utilities /** Hash function applying MAD method to default hash code. */ private int hashValue(K key) { return (int) ((Math.abs(key.hashCode()*scale + shift) % prime) % capacity); } /** Updates the size of the hash table and rehashes all entries. */ private void resize(int

Preview
private class ValueIterable implements Iterable<V> { public Iterator<V> iterator() { return new ValueIterator(); } } //----------- end of nested ValueIterable class ----------- /** * Returns an iterable collection of the values contained in the map. * Note that the same value will be given multiple times in the result *

Preview
increased return answer; } /** * Removes entry having key k from bucket with hash value h, returning * the previously associated value, if found. * @param h the hash value of the relevant bucket * @param k the key of interest * @return previous value associated with k (or

Preview
entry. * @return the entry's key */ K getKey(); /** *

Preview
Returns an iterable collection of the keys contained in the map. * * @return iterable collection of the map's keys */ Iterable<K> keySet(); /** * Returns an iterable collection of the values contained in the map. * Note that the same value will be given multiple times in the result

Preview
//sentinel // provide same constructors as base class /** * Creates a hash table with capacity 17 and prime factor 109345121. */ public ProbeHashMap() { super(); } /** * Creates a hash table with given capacity and prime factor 109345121. */ public ProbeHashMap(int cap) { super(cap); } /** * Creates

Preview
Array with some keys Integer[] key = {11, 27, 21, 18, 32, 44, 55}; // Array with some values Integer[] elem = {1, 4, 5, 3, 5, 2, 4}; // Add some key/elem values in the probehashmap for (int i = 0;

Preview
the probehashmap for (int i = 0; i < key.length; i++) { hashSet.put(key[i],elem[i]); } // Print the content of the hashset for (Object o : hashSet.entrySet()) { System.out.println(o); } // Check size System.out.println("size : " + hashSet.size()); // Check if contains key

Preview
-1) { table.add(new MapEntry<>(key, value)); // add new entry return null; } else // key already exists return table.get(j).setValue(value); // replaced value is returned } /** * Removes the entry with the specified key, if present, and returns its value. * Otherwise does nothing and returns null. * @param key

Screenshots
Purchase Answer

TreeMap-Solution

mariobeka
mariobeka 



In the zip file you'll find the solution of the problem P-11.56.
Implementation + the test drive class for the the TreeMap.
Attachments
Solution.zip (17 K) Download


Preview
* @throws IllegalArgumentException if p is not a valid treemap.Position for this tree. */ @Override public int numChildren(Position<E> p) { int count=0; if (left(p) != null) count++; if (right(p) != null) count++; return count; } /** * Returns an iterable collection of the Positions representing p's children. * * @param

Preview
{ public Iterator<K> iterator() { return new KeyIterator(); } } //----------- end of nested KeyIterable class ----------- /** * Returns an iterable collection of the keys contained in the map. * * @return iterable collection of the map's keys */ @Override public Iterable<K> keySet() { return new KeyIterable(); } //----------------

Preview
// default comparator uses natural ordering } /** * Method for comparing two entries according to key */ protected int compare(Entry<K, V> a, Entry<K, V> b) { return comp.compare(a.getKey(), b.getKey()); } /** * Method for comparing a key and an entry's key */ protected int compare(K a, Entry<K, V> b)

Preview
IllegalArgumentException if p is not a valid treemap.Position for this tree. */ @Override public boolean isExternal(Position<E> p) { return numChildren(p) == 0; } /** * Returns true if treemap.Position p represents the root of the tree. * * @param p A valid treemap.Position within the tree * @return true if

Preview
of x } } /** * Performs a trinode restructuring of treemap.Position x with its parent/grandparent. */ public Position<Entry<K, V>> restructure(Position<Entry<K, V>> x) { Position<Entry<K, V>> y = parent(x); Position<Entry<K, V>> z = parent(y); if ((x == right(y)) == (y == right(z))) {// matching alignments rotate(y);// single rotation (of y)

Preview
the treemap.Position of p's left child (or null if no child exists). * * @param p A valid treemap.Position within the tree * @return the treemap.Position of the left child (or null if no child exists) * @throws IllegalArgumentException if p is not a valid treemap.Position for this tree */

Preview
* @return a negative integer if <tt>a</tt> is less than <tt>b</tt>, * zero if <tt>a</tt> equals <tt>b</tt>,

Preview
* * @return the entry's key */ K getKey(); /** * Returns

Preview
create a new node storing element e. */ protected Node<E> createNode(E e, Node<E> parent, Node<E> left, Node<E> right) { return new Node<E>(e, parent, left, right); } // treemap.LinkedBinaryTree instance variables /** * The root of the binary tree */ protected Node<E> root = null; // root of the tree /**

Preview
that the same value will be given multiple times in the result * if it is associated with multiple keys. * * @return iterable collection of the map's values */ Iterable<V> values(); /** * Returns an iterable collection of all key-value entries of the map. * * @return iterable collection

Preview
* * @return the stored element * @throws IllegalStateException

Preview
with least key greater than or equal to given key * (or null if no such key exists). * @return entry with least key greater than or equal to given (or null if no such entry) * @throws IllegalArgumentException if the key is not compatible with the map */ Entry<K,V>

Preview
entry in the TreeMap: "); System.out.print(treeMap.after(firstEntry)); // Get the entry before the last entry System.out.print("\nThe entry before the last entry in the TreeMap: "); System.out.print(treeMap.before(lastEntry)); // Remove the last entry from the list System.out.print("\nRemove the last entry in the TreeMap: "); System.out.print(treeMap.remove(lastEntry)); // Print the entries in the tree map

Preview
Tree<E> extends Iterable<E> { /** * Returns the root treemap.Position of the tree (or null if tree is empty). * * @return root treemap.Position of the tree (or null if tree is empty) */ Position<E> root(); /** * Returns the treemap.Position of p's parent (or null if p is root).

Preview
map then return null, because there // is no entry after this entry. if (e.equals(lastEntry())) { return null; } else { for (int j = 0; j < entries.length; j++) { if (e.equals(entries[j])) { return entries[j + 1]; } } } return null; } /** * Remove an entry from

Screenshots
Purchase Answer