Design Analysis Algorithm 3
Design Analysis Algorithm 3
Without encoding, the total size of the string was 120 bits. After encoding the size is reduced
to 32 + 15 + 28 = 75.
create a newNode
calculate the sum of these two minimum values and assign it to the value of newNode
return rootNode
• The time complexity for encoding each unique character based on its frequency
is O(nlog n).
• Extracting minimum frequency from the priority queue takes place 2*(n-1) times and its
complexity is O (log n). Thus, the overall complexity is O (nlog n).