In: Computer Science
Must a Huffman tree be a two-tree? Explain
HUFFMAN
TREE:
Huffman coding assigns codes to characters such as the length of
the code depends on the ratio or weight of the corresponding
character. Huffman codes area unit of variable-length, and
prefix-free (no code may be a prefix of any other). Any prefix-free
computer code is often unreal as a binary tree with the encoded
characters keep at the leaves.
Huffman cryptography tree or Huffman tree is a full binary tree
within which every leaf of the tree corresponds to a letter within
the given alphabet.
The Huffman tree is that the binary tree with minimum external path
weight, i.e., the one with the minimum add of weighted path lengths
for the given set of leaves. that the goal is to create a tree with
the minimum external path weight.
There are primarily 2 major parts in Huffman coding:
1) Build a Huffman Tree from input characters.
2) Traverse the assign code of characters.
Three problems:
1.encoding
2.decoding
3.Huffman tree building
1.Encoding:
Encoding a string are often done by replacement every letter within
the string with its computer code (the Huffman code).
Examples:
DEED 10100101 (8 bits)
MUCK 111111001110111101 (18 bits)
2.Decoding:
Decoding AN encoded string is often done by viewing the bits within
the coded string from left to right till a letter decoded.
10100101 -> DEED
3.Huffman tree
building:
A simple algorithm:
1. Prepare a set of n initial Huffman trees, every of that may be a
single leaf node. place the n trees onto a priority queue organized
by weight (frequency).
2. Remove the primary 2 trees (the ones with the bottom weight). be
a part of these 2 trees to make a brand new tree whose root has the
2 trees as youngsters, and whose weight is that the addition of the
weights of the 2 youngsters trees.
3. Put this new tree into the priority queue.
4. Repeat steps 2-3 till all of the partial Huffman trees are
combined into one.
Thank U:)