0
0
DSA Typescriptprogramming~5 mins

Huffman Encoding in DSA Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Huffman Encoding?
Huffman Encoding is a way to compress data by using shorter codes for common letters and longer codes for rare letters. It builds a tree to assign these codes so the total size is smaller.
Click to reveal answer
beginner
What data structure is mainly used in Huffman Encoding?
A binary tree called the Huffman Tree is used. It helps assign codes to characters based on their frequency.
Click to reveal answer
intermediate
How are the codes assigned in Huffman Encoding?
Codes are assigned by traversing the Huffman Tree: going left adds '0' and going right adds '1'. Leaves represent characters with their codes.
Click to reveal answer
intermediate
Why does Huffman Encoding produce a prefix code?
Because no code is the start of another code, so decoding is easy and unambiguous. This happens naturally from the tree structure.
Click to reveal answer
advanced
What is the time complexity to build a Huffman Tree for n unique characters?
It is O(n log n) because we use a priority queue to pick the two smallest frequencies repeatedly until one tree remains.
Click to reveal answer
What does Huffman Encoding use to decide code lengths?
ACharacter frequency
BAlphabetical order
CCharacter ASCII value
DRandom assignment
In Huffman Tree, what does a leaf node represent?
AA character and its code
BA frequency sum
CAn internal node
DA code prefix
What is the first step in building a Huffman Tree?
ABuild a balanced binary tree
BCreate leaf nodes for each character with frequency
CAssign codes randomly
DSort characters alphabetically
Why is Huffman Encoding called a lossless compression?
ABecause it changes data format
BBecause it removes some data
CBecause it uses lossy codes
DBecause original data can be perfectly restored
Which data structure helps efficiently pick the two smallest frequencies in Huffman Encoding?
AStack
BQueue
CPriority queue (min-heap)
DLinked list
Explain how Huffman Encoding builds the tree and assigns codes to characters.
Think about combining smallest frequencies step by step.
You got /5 concepts.
    Why is Huffman Encoding efficient for data compression compared to fixed-length codes?
    Consider how code length relates to character frequency.
    You got /5 concepts.