SlideShare a Scribd company logo
using the code below create a method called getCollisionCount that will return the
number of collisions that occurred when reading a file
Write an application WordFrequency that will be using the Dictionary ADT to study the number
of collisions that occur with different hash table length.
import java.util.Iterator;
import java.util.NoSuchElementException;
public class HashedDictionary implements DictionaryInterface
{
// The dictionary:
private int numberOfEntries;
private static final int DEFAULT_CAPACITY = 5; // Must be prime
private static final int MAX_CAPACITY = 10000;
// The hash table:
private Entry[] hashTable;
private int tableSize; // Must be prime
private static final int MAX_SIZE = 2 * MAX_CAPACITY;
private boolean integrityOK = false;
private static final double MAX_LOAD_FACTOR = 0.5; // Fraction of
// hash table that can be filled
protected final Entry AVAILABLE = new Entry<>(null, null);
public HashedDictionary()
{
this(DEFAULT_CAPACITY); // Call next constructor
} // end default constructor
public HashedDictionary(int initialCapacity)
{
initialCapacity = checkCapacity(initialCapacity);
numberOfEntries = 0; // Dictionary is empty
// Set up hash table:
// Initial size of hash table is same as initialCapacity if it is prime;
// otherwise increase it until it is prime size
tableSize = getNextPrime(initialCapacity);
checkSize(tableSize); // Check that size is not too large
// The cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
Entry[] temp = (Entry[])new Entry[tableSize];
hashTable = temp;
integrityOK = true;
} // end constructor
/* Implementations of methods in DictionaryInterface are here. . . .*/
public boolean isEmpty()
{
return this.numberOfEntries == 0;
}//end isEmpty
public Iterator getValueIterator()
{
throw new NoSuchElementException("Value Iterator Not Implemented");
}//end valueIterator
public void clear()
{
checkIntegrity();
for (int index = 0; index < this.hashTable.length; index++)
{
hashTable[index] = null;
}//end of for
this.numberOfEntries = 0;
}//end clear
public Iterator getKeyIterator()
{
return new KeyIterator();
}//end iterator
public boolean contains(K key)
{
return getValue(key) != null;
}//end contains
public int getSize()
{
return this.numberOfEntries;
}//end getSize
public V remove(K key)
{
throw new NoSuchElementException("Illegal call");
}//end remove
/* END of Implementations of dictionary methods are here^. . . . */
/* Implementations of private methods are here. . . . */
//precondition: checkIntegrity has been called
private void enlargeHashTable()
{
Entry[] oldTable = hashTable;
int oldSize = hashTable.length;
int newSize = getNextPrime(oldSize + oldSize);
checkSize(newSize);
//The cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
Entry[] temp = (Entry[]) new Entry[newSize];
hashTable = temp;
numberOfEntries = 0;//reset number of dictionary entries, since it will be incremented by add
during rehash
//rehash dictionary entries from old array to the new and bigger array;
//skip elements that contain null or available
for(int index = 0; index < oldSize; index++)
{
if((oldTable[index] != null) && (oldTable[index] != AVAILABLE))
{
add(oldTable[index].getKey(), oldTable[index].getValue());
}
}// end for
}//end enlargeHashTable
private int getHashIndex(K key)
{
int hashIndex = key.hashCode() % hashTable.length;
if(hashIndex < 0)
{
hashIndex = hashIndex + hashTable.length;
}
return hashIndex;
}//end getHashIndex
private void checkIntegrity()
{
if(!integrityOK)
{
throw new SecurityException("objecy is currupt");
}
}//end checkIntegrity
private boolean isHashTableTooFull()
{
if((numberOfEntries / hashTable.length) >= MAX_LOAD_FACTOR)
{
return true;
}
else
{
return false;
}
}//end isHashTableTooFull
private int checkSize(int size)
{
if(size >= MAX_SIZE){throw new IllegalStateException("Dictionary has become too large.");}
else{return size;}
}//end checksize
private int checkCapacity(int cap)
{
if(cap < DEFAULT_CAPACITY)
{
cap = DEFAULT_CAPACITY;
}
else if (cap > MAX_CAPACITY)
{
throw new IllegalStateException("Attempt to create a dictionary " + "whose capacity is larger
than " + MAX_CAPACITY);
}
return cap;
}//end checkcap
private int getNextPrime(int integer)
{
// if even, add 1 to make od
if (integer % 2 == 0)
{
integer++;
} // end if
// test odd integers
while (!isPrime(integer))
{
integer = integer + 2;
} // end while
return integer;
}//end getnextprime
private boolean isPrime(int integer)
{
boolean result;
boolean done = false;
// 1 and even numbers are not prime
if ( (integer == 1) || (integer % 2 == 0) )
{
result = false;
}
// 2 and 3 are prime
else if ( (integer == 2) || (integer == 3) )
{
result = true;
}
else // integer is odd and >= 5
{
assert (integer % 2 != 0) && (integer >= 5);
// a prime is odd and not divisible by every odd integer up to its square root
result = true; // assume prime
for (int divisor = 3; !done && (divisor * divisor <= integer); divisor = divisor + 2)
{
if (integer % divisor == 0)
{
result = false; // divisible; not prime
done = true;
} // end if
} // end for
} // end if
return result;
} // end isPrime
/* END of Implementations of private methods are here^. . . . */
protected final class Entry
{
private K key;
private V value;
private Entry(K searchKey, V dataValue)
{
key = searchKey;
value = dataValue;
}//end contructor
private K getKey()
{
return key;
}//end getKey
private V getValue()
{
return value;
}//end value
private void setValue(V newValue)
{
value = newValue;
}//end setValue
} // end Entry
//Required Methods
private class KeyIterator implements Iterator
{
private int currentIndex; // Current position in hash table
private int numberLeft; // Number of entries left in iteration
private KeyIterator()
{
currentIndex = 0;
numberLeft = numberOfEntries;
} // end default constructor
public boolean hasNext()
{
return numberLeft > 0;
} // end hasNext
public void remove()
{
throw new UnsupportedOperationException();
} // end remove
public K next()
{
K result = null;
if (hasNext())
{
// Skip table locations that do not contain a current entry
while ( (hashTable[currentIndex] == null) ||
(hashTable[currentIndex] == AVAILABLE) )
{
currentIndex++;
} // end while
result = hashTable[currentIndex].getKey();
numberLeft--;
currentIndex++;
}
else
throw new NoSuchElementException();
return result;
} // end next
} // end KeyIterator
public V getValue(K key)
{
checkIntegrity();
V result = null;
int index = getHashIndex(key);
if ((hashTable[index] != null) && (hashTable[index] != AVAILABLE))
result = hashTable[index].getValue(); // Key found; get value
// Else key not found; return null
return result;
} // end getValue
public V add(K key, V value)
{
int index;
V oldValue;
if((key == null) || (value == null))
{
throw new NoSuchElementException();
}
index = getHashIndex(key);
if((hashTable[index] != null) && (hashTable[index] != AVAILABLE))
{
hashTable[index] = new Entry(key,value);
numberOfEntries++;
oldValue = null;
}
else
{
oldValue = hashTable[index].getValue();
hashTable[index].setValue(value);
}
if(isHashTableTooFull())
{
enlargeHashTable();
}
return oldValue;
}
//end of require methods
//getCollisionCount method
public int getCollisionCount()
{
//code implementation
return 1;
}
} // end HashedDictionary

More Related Content

Similar to using the code below create a method called getCollisionCount that w.pdf

Answer this question for quality assurance. Include a final applicat.pdf
Answer this question for quality assurance. Include a final applicat.pdfAnswer this question for quality assurance. Include a final applicat.pdf
Answer this question for quality assurance. Include a final applicat.pdf
akanshanawal
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
shyamsunder1211
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
 
Google guava
Google guavaGoogle guava
Lecture 6.pptx
Lecture 6.pptxLecture 6.pptx
Lecture 6.pptx
vinayjod
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
SHIVA101531
 
Class ‘increment’
Class ‘increment’Class ‘increment’
Class ‘increment’
Syed Zaid Irshad
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
ssuser562afc1
 
Inheritance compiler support
Inheritance compiler supportInheritance compiler support
Inheritance compiler support
Syed Zaid Irshad
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
mail931892
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.
Russell Childs
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
fmac5
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
arjuncorner565
 
What’s new in C# 6
What’s new in C# 6What’s new in C# 6
What’s new in C# 6
Fiyaz Hasan
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
ChereCheek752
 

Similar to using the code below create a method called getCollisionCount that w.pdf (20)

Answer this question for quality assurance. Include a final applicat.pdf
Answer this question for quality assurance. Include a final applicat.pdfAnswer this question for quality assurance. Include a final applicat.pdf
Answer this question for quality assurance. Include a final applicat.pdf
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
 
Google guava
Google guavaGoogle guava
Google guava
 
Lecture 6.pptx
Lecture 6.pptxLecture 6.pptx
Lecture 6.pptx
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
 
Class ‘increment’
Class ‘increment’Class ‘increment’
Class ‘increment’
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
 
Inheritance compiler support
Inheritance compiler supportInheritance compiler support
Inheritance compiler support
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
What’s new in C# 6
What’s new in C# 6What’s new in C# 6
What’s new in C# 6
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 

More from amirthagiftsmadurai

value if lifo for its inverntory. the inventory on12312020 was $70.pdf
value if lifo for its inverntory. the inventory on12312020 was $70.pdfvalue if lifo for its inverntory. the inventory on12312020 was $70.pdf
value if lifo for its inverntory. the inventory on12312020 was $70.pdf
amirthagiftsmadurai
 
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdfUtilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
amirthagiftsmadurai
 
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdfUsted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
amirthagiftsmadurai
 
Using this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdfUsing this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdf
amirthagiftsmadurai
 
using the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdfusing the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdf
amirthagiftsmadurai
 
Using the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdfUsing the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdf
amirthagiftsmadurai
 
Using the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdfUsing the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdf
amirthagiftsmadurai
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
amirthagiftsmadurai
 
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset  how to conduct a comprehensive EDA .pdfUsing the accidentdata dataset  how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
amirthagiftsmadurai
 
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdfVuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
amirthagiftsmadurai
 
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdfVuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
amirthagiftsmadurai
 
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdfWe aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
amirthagiftsmadurai
 
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdfVerdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
amirthagiftsmadurai
 
Verdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdfVerdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdf
amirthagiftsmadurai
 
Warren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdfWarren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdf
amirthagiftsmadurai
 
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdfWatch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
amirthagiftsmadurai
 
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdfVincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
amirthagiftsmadurai
 
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdfWanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
amirthagiftsmadurai
 
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdfW1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
amirthagiftsmadurai
 
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdfVerdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
amirthagiftsmadurai
 

More from amirthagiftsmadurai (20)

value if lifo for its inverntory. the inventory on12312020 was $70.pdf
value if lifo for its inverntory. the inventory on12312020 was $70.pdfvalue if lifo for its inverntory. the inventory on12312020 was $70.pdf
value if lifo for its inverntory. the inventory on12312020 was $70.pdf
 
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdfUtilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
Utilizando los datos comerciales del Observatorio de Complejidad Eco.pdf
 
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdfUsted es accionista del 5  de Company XYZ, Inc. La compa��a planea .pdf
Usted es accionista del 5 de Company XYZ, Inc. La compa��a planea .pdf
 
Using this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdfUsing this example code in Xcode, please help with this project wher.pdf
Using this example code in Xcode, please help with this project wher.pdf
 
using the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdfusing the the periodic method what is the journal entryusing th.pdf
using the the periodic method what is the journal entryusing th.pdf
 
Using the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdfUsing the properties of Regular languages, mention which properties .pdf
Using the properties of Regular languages, mention which properties .pdf
 
Using the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdfUsing the information displayed on the table below, calculate the Un.pdf
Using the information displayed on the table below, calculate the Un.pdf
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
 
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset  how to conduct a comprehensive EDA .pdfUsing the accidentdata dataset  how to conduct a comprehensive EDA .pdf
Using the accidentdata dataset how to conduct a comprehensive EDA .pdf
 
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdfVuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
Vuelva a resolver el problema 15 de la secci�n 2.2 de su texto, que .pdf
 
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdfVuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
Vuelve a escribir las oraciones usando los verbos provistos entre pa.pdf
 
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdfWe aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
We aim to upgrade the function �insert� of the class orderedLinkedLi.pdf
 
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdfVerdadero o falso 7. Los errores son errores no intencionales. .pdf
Verdadero o falso 7. Los errores son errores no intencionales. .pdf
 
Verdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdfVerdadero o falso todas las especies, independientemente de los tax.pdf
Verdadero o falso todas las especies, independientemente de los tax.pdf
 
Warren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdfWarren Buffy is an enormously wealthy investor who has built his for.pdf
Warren Buffy is an enormously wealthy investor who has built his for.pdf
 
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdfWatch Podcast SpanxWrite a response to the podcast using the cor.pdf
Watch Podcast SpanxWrite a response to the podcast using the cor.pdf
 
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdfVincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
Vincent van Gogh es uno de los artistas postimpresionistas m�s conoc.pdf
 
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdfWanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
Wanda, a retired electrical engineer, suffered a stroke, Her memorie.pdf
 
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdfW1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
W1X2Y3ZA chemolithoautotroph uses as an energy source, as an electr.pdf
 
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdfVerdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
Verdadero Falso. Dado que Yt es una serie de tiempo multivariante, s.pdf
 

Recently uploaded

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 

Recently uploaded (20)

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

using the code below create a method called getCollisionCount that w.pdf

  • 1. using the code below create a method called getCollisionCount that will return the number of collisions that occurred when reading a file Write an application WordFrequency that will be using the Dictionary ADT to study the number of collisions that occur with different hash table length. import java.util.Iterator; import java.util.NoSuchElementException; public class HashedDictionary implements DictionaryInterface { // The dictionary: private int numberOfEntries; private static final int DEFAULT_CAPACITY = 5; // Must be prime private static final int MAX_CAPACITY = 10000; // The hash table: private Entry[] hashTable; private int tableSize; // Must be prime private static final int MAX_SIZE = 2 * MAX_CAPACITY; private boolean integrityOK = false; private static final double MAX_LOAD_FACTOR = 0.5; // Fraction of // hash table that can be filled protected final Entry AVAILABLE = new Entry<>(null, null); public HashedDictionary() { this(DEFAULT_CAPACITY); // Call next constructor } // end default constructor public HashedDictionary(int initialCapacity) { initialCapacity = checkCapacity(initialCapacity); numberOfEntries = 0; // Dictionary is empty // Set up hash table: // Initial size of hash table is same as initialCapacity if it is prime;
  • 2. // otherwise increase it until it is prime size tableSize = getNextPrime(initialCapacity); checkSize(tableSize); // Check that size is not too large // The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") Entry[] temp = (Entry[])new Entry[tableSize]; hashTable = temp; integrityOK = true; } // end constructor /* Implementations of methods in DictionaryInterface are here. . . .*/ public boolean isEmpty() { return this.numberOfEntries == 0; }//end isEmpty public Iterator getValueIterator() { throw new NoSuchElementException("Value Iterator Not Implemented"); }//end valueIterator public void clear() { checkIntegrity(); for (int index = 0; index < this.hashTable.length; index++) {
  • 3. hashTable[index] = null; }//end of for this.numberOfEntries = 0; }//end clear public Iterator getKeyIterator() { return new KeyIterator(); }//end iterator public boolean contains(K key) { return getValue(key) != null; }//end contains public int getSize() { return this.numberOfEntries; }//end getSize public V remove(K key) { throw new NoSuchElementException("Illegal call"); }//end remove /* END of Implementations of dictionary methods are here^. . . . */ /* Implementations of private methods are here. . . . */
  • 4. //precondition: checkIntegrity has been called private void enlargeHashTable() { Entry[] oldTable = hashTable; int oldSize = hashTable.length; int newSize = getNextPrime(oldSize + oldSize); checkSize(newSize); //The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") Entry[] temp = (Entry[]) new Entry[newSize]; hashTable = temp; numberOfEntries = 0;//reset number of dictionary entries, since it will be incremented by add during rehash //rehash dictionary entries from old array to the new and bigger array; //skip elements that contain null or available for(int index = 0; index < oldSize; index++) { if((oldTable[index] != null) && (oldTable[index] != AVAILABLE)) { add(oldTable[index].getKey(), oldTable[index].getValue()); } }// end for }//end enlargeHashTable private int getHashIndex(K key) { int hashIndex = key.hashCode() % hashTable.length; if(hashIndex < 0) { hashIndex = hashIndex + hashTable.length; }
  • 5. return hashIndex; }//end getHashIndex private void checkIntegrity() { if(!integrityOK) { throw new SecurityException("objecy is currupt"); } }//end checkIntegrity private boolean isHashTableTooFull() { if((numberOfEntries / hashTable.length) >= MAX_LOAD_FACTOR) { return true; } else { return false; } }//end isHashTableTooFull private int checkSize(int size) { if(size >= MAX_SIZE){throw new IllegalStateException("Dictionary has become too large.");} else{return size;} }//end checksize
  • 6. private int checkCapacity(int cap) { if(cap < DEFAULT_CAPACITY) { cap = DEFAULT_CAPACITY; } else if (cap > MAX_CAPACITY) { throw new IllegalStateException("Attempt to create a dictionary " + "whose capacity is larger than " + MAX_CAPACITY); } return cap; }//end checkcap private int getNextPrime(int integer) { // if even, add 1 to make od if (integer % 2 == 0) { integer++; } // end if // test odd integers while (!isPrime(integer)) { integer = integer + 2; } // end while return integer; }//end getnextprime
  • 7. private boolean isPrime(int integer) { boolean result; boolean done = false; // 1 and even numbers are not prime if ( (integer == 1) || (integer % 2 == 0) ) { result = false; } // 2 and 3 are prime else if ( (integer == 2) || (integer == 3) ) { result = true; } else // integer is odd and >= 5 { assert (integer % 2 != 0) && (integer >= 5); // a prime is odd and not divisible by every odd integer up to its square root result = true; // assume prime for (int divisor = 3; !done && (divisor * divisor <= integer); divisor = divisor + 2) { if (integer % divisor == 0) { result = false; // divisible; not prime done = true; } // end if } // end for } // end if return result; } // end isPrime /* END of Implementations of private methods are here^. . . . */
  • 8. protected final class Entry { private K key; private V value; private Entry(K searchKey, V dataValue) { key = searchKey; value = dataValue; }//end contructor private K getKey() { return key; }//end getKey private V getValue() { return value; }//end value private void setValue(V newValue) { value = newValue; }//end setValue } // end Entry //Required Methods private class KeyIterator implements Iterator { private int currentIndex; // Current position in hash table private int numberLeft; // Number of entries left in iteration private KeyIterator() {
  • 9. currentIndex = 0; numberLeft = numberOfEntries; } // end default constructor public boolean hasNext() { return numberLeft > 0; } // end hasNext public void remove() { throw new UnsupportedOperationException(); } // end remove public K next() { K result = null; if (hasNext()) { // Skip table locations that do not contain a current entry while ( (hashTable[currentIndex] == null) || (hashTable[currentIndex] == AVAILABLE) ) { currentIndex++; } // end while result = hashTable[currentIndex].getKey(); numberLeft--; currentIndex++; } else throw new NoSuchElementException(); return result; } // end next } // end KeyIterator public V getValue(K key)
  • 10. { checkIntegrity(); V result = null; int index = getHashIndex(key); if ((hashTable[index] != null) && (hashTable[index] != AVAILABLE)) result = hashTable[index].getValue(); // Key found; get value // Else key not found; return null return result; } // end getValue public V add(K key, V value) { int index; V oldValue; if((key == null) || (value == null)) { throw new NoSuchElementException(); } index = getHashIndex(key); if((hashTable[index] != null) && (hashTable[index] != AVAILABLE)) { hashTable[index] = new Entry(key,value); numberOfEntries++; oldValue = null; } else { oldValue = hashTable[index].getValue(); hashTable[index].setValue(value); } if(isHashTableTooFull()) { enlargeHashTable(); } return oldValue;
  • 11. } //end of require methods //getCollisionCount method public int getCollisionCount() { //code implementation return 1; } } // end HashedDictionary