Need help with this paper This assignment consists of writing research paper sur
ID: 3787236 • Letter: N
Question
Need help with this paper
This assignment consists of writing research paper surveying a popular algorithm. Your paper must conform to
the American Psychological Association (APA) writing style.
There are many good online resources for the APA style.Your paper must use reputable scholarly references. Most Web sources such as blog, forums, and personal website are not considered reputable(do not cite or use any Wiki or Answer.com type websites). Your paper should use 11pt or 12pt font size for the main text. Other text such as figure and table labels and captions, if applicable, should be no smaller then 10pt. A typical research paper for this assignment is about 7-10 double spaced pages (not including the cover page or reference page).
Topics:
Choose one of the following algorithms areas to write about. Potential algorithm topics related to the algorithm area are included in parenthesis as examples.
1.Hashing Algorithms (e.g.SHA-3;Message Digest-5;Cryptography algorithms such as Advanced Encryption Standard, Blowfish,Elliptic curve cryptography;Digital signature algorithms; Bitcoin Mining)
2.Compression Algorithms (e.g. LZO, Data differencing, Huffman Coding)
3.String Matching (e.g Google’s PageRank algorithm , DNA sequence algorithms, Spell checking algorithms)
4.Memory Management (e.g. Garbage Collection, Buddy Methods, Paging algorithms,Sequential-Fit Methods)
Explanation / Answer
public final category Huffman non-public Huffman() ;
non-public static category HuffmanNode
}
non-public static category HuffManComparator implements Comparator<HuffmanNode> come back node1.frequency - node2.frequency;
}
}
/**
* Compresses the string victimisation huffman formula.
* The huffman tree and also the huffman code area unit serialized to disk
*
* @param sentence The sentence to be serialized
* @throws FileNotFoundException If file isn't found
* @throws IOException If IO exception happens.
*/
public static void compress(String sentence) throws FileNotFoundException, IOException ought to atleast have one character.");
}
final Map<Character, Integer> charFreq = getCharFrequency(sentence);
final HuffmanNode root = buildTree(charFreq);
final Map<Character, String> charCode = generateCodes(charFreq.keySet(), root);
final String encodedMessage = encodeMessage(charCode, sentence);
serializeTree(root);
serializeMessage(encodedMessage);
}
non-public static Map<Character, Integer> getCharFrequency(String sentence) else
}
come map;
}
/**
* Map<Character, Integer> map
* Some implementation of that treeSet is passed as parameter.
* @param map
*/
non-public static HuffmanNode buildTree(Map<Character, Integer> map) whereas (nodeQueue.size() > 1)
// take away it to forestall object leak.
come nodeQueue.remove();
}
non-public static Queue<HuffmanNode> createNodeQueue(Map<Character, Integer> map)
return pq;
}
non-public static Map<Character, String> generateCodes(Set<Character> chars, HuffmanNode node) {
final Map<Character, String> map = new HashMap<Character, String>();
doGenerateCode(node, map, "");
come map;
}
non-public static void doGenerateCode(HuffmanNode node, Map<Character, String> map, String s)
doGenerateCode(node.left, map, s + '0');
doGenerateCode(node.right, map, s + '1' );
}
non-public static String encodeMessage(Map<Character, String> charCode, String sentence)
come stringBuilder.toString();
}
non-public static void serializeTree(HuffmanNode node) throws FileNotFoundException, IOException attempt (ObjectOutputStream oosTree = new ObjectOutputStream(new FileOutputStream("/Users/ap/Desktop/tree"))) strive (ObjectOutputStream oosChar = new ObjectOutputStream(new FileOutputStream("/Users/ap/Desktop/char"))) soft to mark finish of bit set relevant for deserialization.
oosTree.writeObject(bitSet);
}
}
}
non-public static category IntObject
/*
* Algo:
* 1. Access the node
* 2. Register the worth in bit set.
*
*
* here true and false dont correspond to left branch and right branch.
* there,
* - true means that "a branch originates from leaf"
* - false mens "a branch originates from non-left".
*
* additionally since branches originate from some node, the foundation node should be provided as supply
* or place to begin of initial branches.
*
* Diagram and the way associate degree bit set would look as a result.
* (source node)
* /
* true true
* /
* (leaf node) (leaf node)
* | |
* false false
* | |
*
* thus currently somewhat set appears like [false, true, false, true]
*
*/
non-public static void preOrder(HuffmanNode node, ObjectOutputStream oosChar, BitSet bitSet, IntObject intObject) throws IOException
bitSet.set(intObject.bitPosition++, true); // register branch in bitset
preOrder(node.left, oosChar, bitSet, intObject); // take the branch.
bitSet.set(intObject.bitPosition++, true); // register branch in bitset
preOrder(node.right, oosChar, bitSet, intObject); // take the branch.
}
non-public static void serializeMessage(String message) throws IOException attempt (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("/Users/ap/Desktop/encodedMessage")))
}
non-public static BitSet getBitSet(String message) else
}
bitSet.set(i, true); // dummy bit set to grasp the length
come bitSet;
}
/**
* Retrieves back the initial string.
*
*
* @return the initial uncompressed string
* @throws FileNotFoundException If the file isn't found
* @throws ClassNotFoundException If category isn't found
* @throws IOException If IOException happens
*/
public static String expand() throws FileNotFoundException, ClassNotFoundException, IOException {
final HuffmanNode root = deserializeTree();
come decodeMessage(root);
}
non-public static HuffmanNode deserializeTree() throws FileNotFoundException, IOException, ClassNotFoundException strive (ObjectInputStream oisBranch = new ObjectInputStream(new FileInputStream("/Users/ap/Desktop/tree"))) strive (ObjectInputStream oisChar = new ObjectInputStream(new FileInputStream("/Users/ap/Desktop/char"))) agencyBranch.readObject();
come preOrder(bitSet, oisChar, new IntObject());
}
}
}
/*
* Construct a tree from:
* input [false, true, false, true, (dummy faithful mark the top of bit set)]
* The input is built from preorder traversal
*
* Algo:
* one produce the node.
* 2. scan what's registered in bitset, and judge if created node is meant to be a leaf or non-leaf
*
*/
non-public static HuffmanNode preOrder(BitSet bitSet, ObjectInputStream oisChar, IntObject o) throws IOException crucial if created node is that the leaf or non-leaf.
if (!bitSet.get(o.bitPosition)) succeeding position to subsequent stack frame by doing computation before preOrder is named.
node.ch = oisChar.readChar();
come node;
}
o.bitPosition = o.bitPosition + 1; // feed subsequent position to subsequent stack frame by doing computation before preOrder is named.
node.left = preOrder(bitSet, oisChar, o);
o.bitPosition = o.bitPosition + 1; // feed subsequent position to subsequent stack frame by doing computation before preOrder is named.
node.right = preOrder(bitSet, oisChar, o);
come node;
}
non-public static String decodeMessage(HuffmanNode node) throws FileNotFoundException, IOException, ClassNotFoundException strive (ObjectInputStream Office of Intelligence Support = new ObjectInputStream(new FileInputStream("/Users/ameya.patil/Desktop/encodedMessage"))) worker = node;
// since huffman code generates full binary tree, temp.right is definitely null if temporary worker.left is null.
whereas (temp.left != null) {
if (!bitSet.get(i)) {
temporary worker = temporary worker.left;
} else {
temporary worker = temporary worker.right;
}
i = i + 1;
}
stringBuilder.append(temp.ch);
}
come stringBuilder.toString();
}
}
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException range of characters
Huffman.compress("some");
Assert.assertEquals("some", Huffman.expand());
// odd range of characters
Huffman.compress("someday");
Assert.assertEquals("someday", Huffman.expand());
// continuance even range of characters + area + non-ascii
Huffman.compress("some some#");
Assert.assertEquals("some some#", Huffman.expand());
// odd range of characters + area + non-ascii
Huffman.compress("someday someday&");
Assert.assertEquals("someday someday&", Huffman.expand());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.