Question: Objectives: To Determine the codes to be used for transmitting your name using Huffman coding. Deliverables: Huffman code of your name, along with answers to
Objectives:
To Determine the codes to be used for transmitting your name using Huffman coding.
Deliverables:
Huffman code of your name, along with answers to the given questions.
Background information : In the field of multimedia content development, understanding the factors that influence the quality of images, sound, and other elements is crucial. One such factor is the efficiency of data compression techniques. Huffman coding is a widelyused method for lossless data compression. The idea is to assign variablelength codes to input characters, lengths of the assigned codes are based on the frequencies of corresponding characters. The most frequent character gets the smallest code and the least frequent character gets the largest code. The variablelength codes assigned to input characters are Prefix Codes, means the codes bit sequences are assigned in such a way that the code assigned to one character is not the prefix of code assigned to any other character. This is how Huffman Coding makes sure that there is no ambiguity when decoding the generated bitstream. Reference : geeksforgeeks.com Your task is to evaluate how Huffman coding can contribute to enhancing multimedia content quality, particularly focusing on the compression of textual data. Follow the steps below to complete this task:
Your report will be evaluated based on the following points.
Executed the given java program and got the output
Huffman code of your name is written properly
All the given tasks are completed successfully
CLO marks marks
Task
Copy the following program and save it as Huffman.py
Execute the program give and check the output
Take snapshot of the output along with timestamp.
The output shows the codes used for each letter of your name.
University of Fujairah
BITNetworking and Security Program
Task
Answer the following :
Determine the maximum length of the code used and for which letter it is used?
Determine the letter which gets shortest length code?
Task :
Draw a table as given in the example.
Eg:
MULTIMEDIA
Text: MULTIMEDIA
intervals
A :
D :
E :
I :
L :
M :
T :
U :
Printing Codes
A :
D :
E :
I :
L :
M :
T :
University of Fujairah
BITNetworking and Security Program
U :
EncodingDecoding
Encoded Text:
Decoded Text: MULTIMEDIA
Arrange them as given in the following table
LETTER
M
U
L
T
I
M
E
D
I
A
FREQUNCY
REPETITION
REPETITION
CODE USED
Task :
Arranging the entries in order
Write them without repetition, and in descending order of frequency
LETTER
I
M
E
U
L
A
T
D
FREQUNCY
CODE USED
Write your inference from the above table.
University of Fujairah
BITNetworking and Security Program
Huffman.py
from heapq import heappush, heappop, heapify
from collections import defaultdict
class Node:
def initself char, freq:
self.char char
self.freq freq
self.left None
self.right None
def ltself other:
return self.freq other.freq
def buildhuffmantreefreqmap:
heap Nodechar freq for char, freq in freqmap.items
heapifyheap
while lenheap:
left heappopheap
right heappopheap
merged NodeNone left.freq right.freq
merged.left left
merged.right right
heappushheap merged
University of Fujairah
BITNetworking and Security Program
return heap
def generatecodesroot code codes:
if root is not None:
if root.char is not None:
codesrootchar code
generatecodesrootleft, code codes
generatecodesrootright, code codes
def huffmanencodingtext:
freqmap defaultdictint
for char in text:
freqmapchar
if lenfreqmap:
return : text
root buildhuffmantreefreqmap
codes
generatecodesroot codes
encodedtext joincodeschar for char in text
return codes, encodedtext
def huffmandecodingcodes encodedtext:
decodedtext
reversecodes v: k for k v in codes.items
University of Fujairah
BITNetworking and Security Program
code
for bit in encodedtext:
code bit
if code in reversecodes:
decodedtext reversecodescode
code
return decodedtext
def main:
text inputEnter the text:
codes, encodedtext huffmanencodingtext
printEncoded text:", encodedtext
printFrequency count and codes:"
for char, code in codes.items:
printfchar: code
decodedtext huffmandecodingcodes encodedtext
printDecoded text:", deco
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
