You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Competitive Coding/Greedy/Huffman Coding/Readme.md
+6
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,15 @@ It follows a Greedy approach since it deals with generating minimum length prefi
4
4
It uses variable-length encoding scheme for assigning binary codes to characters depending on how frequently they occur in the given text.
5
5
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.
6
6
It follows this procedure: -
7
+
7
8
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
+
8
10
Repeat Steps 3 to 5 while heap has more than one node
11
+
9
12
Extract two nodes, say x and y, with minimum frequency from the heap
13
+
10
14
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
+
11
16
Add z to min heap
17
+
12
18
Last node in the heap is the root of Huffman tree
0 commit comments