Skip to content

Commit 868f790

Browse files
authored
Update Readme.md
1 parent 52c3c77 commit 868f790

File tree

1 file changed

+6
-0
lines changed
  • Competitive Coding/Greedy/Huffman Coding

1 file changed

+6
-0
lines changed

Competitive Coding/Greedy/Huffman Coding/Readme.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ It follows a Greedy approach since it deals with generating minimum length prefi
44
It uses variable-length encoding scheme for assigning binary codes to characters depending on how frequently they occur in the given text.
55
Priority Queue is used for building the Huffman tree such that the character that occurs most frequently is assigned the smallest code and the one that occurs least frequently gets the largest code.
66
It follows this procedure: -
7+
78
Create a leaf node for each character and build a min heap using all the nodes (The frequency value is used to compare two nodes in min heap)
9+
810
Repeat Steps 3 to 5 while heap has more than one node
11+
912
Extract two nodes, say x and y, with minimum frequency from the heap
13+
1014
Create a new internal node z with x as its left child and y as its right child. Also frequency(z)= frequency(x)+frequency(y)
15+
1116
Add z to min heap
17+
1218
Last node in the heap is the root of Huffman tree

0 commit comments

Comments
 (0)