Hi all,
I understand the underlying concepts behind the generation of a Huffman Tree and can do it on paper; the problem is converting the concept into a routine/program.
This is what I'm hoping to accomplish: http://huffman.ooz.ie/?text=This%20is%20a%20test%20string
So far I've been able to create and organise the frequency table. I don't know what the next step is. I know, however, that I need to begin with the two lowest frequencies and sum them up then repeat. I'm uncertain as to how I can accomplish this and generate a tree. A 2D, 3D array? Some queer data type?
Any help would be highly appreciated, thanks!
AutoIt
#include <Array.au3> $time = TimerInit() $str = "This is a test string" $var = StringSplit($str, "") Dim $trie[1][2] $trie[0][0] = $str $trie[0][1] = $var[0] For $i = 1 To $var[0] For $j = 1 To UBound($trie)-1 If $trie[$j][0] == $var[$i] Then $trie[$j][1] += 1 ContinueLoop 2 EndIf Next ReDim $trie[$j + 1][2] $trie[$j][0] = $var[$i] $trie[$j][1] = 1 Next ConsoleWrite("Execution time: " & TimerDiff($time) & "ms" & @LF) _ArraySort($trie, 1, 0, 0, 1) _ArrayDisplay($trie) $trie[UBound($trie)-2][0] = $trie[UBound