Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following set of character-probability pairs: (2, 0, 2), (2, 0, 2), (0

ID: 3687559 • Letter: G

Question

Given the following set of character-probability pairs: (2, 0, 2), (2, 0, 2), (0, 0, ), (, 0, ), (, 0, 2) (The probability associated with each character is the probability accurring in the text to be compressed.) Build a Haffman tree for this character set. Fill in the following table to show the leaves queue (S) and the trees queue (T) be the end of each step. Assume the enqueue, dequeue, pick, creating a leaf mode, creating a new tree out of two subtrees, and picking the minimum of two probabilities all take unit time. Ignore the time for all other operations. How many units of time did it take in all to build your tree? Show your work.

Explanation / Answer

Huffman Algorithm for Building a Tree

1. Scan text to be compressed and tally occurrence of all characters.

2. Sort or prioritize characters based on number of occurrences in text.

3. Build Huffman code tree based on prioritized list.

4. Perform a traversal of tree to determine all code words.

5. Scan text again and create new file using the Huffman codes.

·Create binary tree nodes with character and frequency of each character

·Place nodes in a priority queue

–The lower the occurrence, the higher the priority in the queue

·While priority queue contains two or more nodes

–Create new node

–Dequeue node and make it left subtree

–Dequeue next node and make it right subtree

–Frequency of new node equals sum of frequency of left and right children

–Enqueue new node back into queue

Complexity for each of the individual points in the Algorithm :

•Sort keys             O(n log n)

•Repeat n times

•Form new sub-tree O(1)

•Move sub-tree O(logn) (binary search)

•Total                O(n log n)

•Overall    O(n log n)  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote