Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic Huffman Trees Sibling property: there is an ordering of nodes such that C(n i )<=C( ni+1 ) for all i and for each adjacent pair of nodes n 2k-1,

Similar presentations


Presentation on theme: "Dynamic Huffman Trees Sibling property: there is an ordering of nodes such that C(n i )<=C( ni+1 ) for all i and for each adjacent pair of nodes n 2k-1,"— Presentation transcript:

1 Dynamic Huffman Trees Sibling property: there is an ordering of nodes such that C(n i )<=C( ni+1 ) for all i and for each adjacent pair of nodes n 2k-1, n 2k are siblings in the Tree.

2 Example Ordering is 0123456 0111224

3 Overflow

4 Overflow Part 2

5 Alles unter Kontrolle

6 Keeping track of Ordering (one idea) Use Array representation of tree. –Store child/parent offsets (can’t use implicit representation, since Huffman trees aren’t necessarily “complete”) (more clever) See if you can use pointers to require only 1 lookup to find the swap-node

7 Increment Letter Procedure IncrementLetter (letter) letterPos = position of letter in Array representation of tree suspectPos = letterPos While suspectPos is not Root Increment Count(letterPos) If Count(suspectPos) > Count(suspectPos - 1) Then { it got out of order } lastOfCount = lowest #’d array index whose count is the same as Count(suspectPos) used to be Swap sub-Trees at lastOfCount, suspectPos Else { everything’s fine now } Exit While End If suspectPos = Parent(lastOfCount) End While

8 Put new letter into tree Procedure InsertNewLetter (newLetter) { the NULL character is the special signal for a new character } Replace NULL node with newParentNode Make newParentNode a Parent of (NULL, newLetter) Run IncrementLetter algorithm on newLetter

9 Exercise Process 11-character text using dynamic Huffman tree. Write the encoding. Periodically check if static tree would be the same Use Array (used for Heap) or draw by hand. Text: The rather rash hero rode a horse that dashed with a wet head and dared to rise. It hid with tethered teeth that saw a sorrow. Oh, are these withered arrows of teeth so arid in war? Or has the horse the ride of heroes ridden in its hidden dose of worth? Letters: adefh iorst w (11 letters)


Download ppt "Dynamic Huffman Trees Sibling property: there is an ordering of nodes such that C(n i )<=C( ni+1 ) for all i and for each adjacent pair of nodes n 2k-1,"

Similar presentations


Ads by Google