Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program in C language to generate Huffman coding for the following Text given: ADAM IS IN MADAMS KITCHEN ( make sure the output
Write a program in C language to generate Huffman coding for the following Text given:
ADAM IS IN MADAMS KITCHEN
make sure the output is in the exact same order as shown in the testcase in results Here i have given the eqivalent program in : import heapq
import collections
def huffmancodingtext:
# Frequency of each character
frequency collections.Countertext
# Priority queue to hold the characters and their frequencies
priorityqueue weightsymbol for symbol, weight in frequency.items
heapq.heapifypriorityqueue
# Tree construction
while lenpriorityqueue:
low heapq.heappoppriorityqueue
high heapq.heappoppriorityqueue
for pair in low::
pair pair
for pair in high::
pair pair
heapq.heappushpriorityqueue, low high low: high:
# Generating Huffman codes
huffmancodes
for pair in heapq.heappoppriorityqueue::
huffmancodespair pair
return frequency, huffmancodes
text "ADAM IS IN MADAMS KITCHEN"
frequency, huffmancodes huffmancodingtextreplace
printFREQUENCY OF ALPHABETS"
specificorder AMIDSNKTCHE
for char in specificorder:
if char in frequency:
printfcharfrequencychar
printHUFFMAN CODE IS
for char, code in sortedhuffmancodes.items keylambda x: lenx x:
printfcharcode
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started