Question: 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
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
