1 / 9

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. Dynamic Huffman Trees. Example. Ordering is. Overflow. Overflow Part 2. Alles unter Kontrolle. Keeping track of Ordering.

Download Presentation

Dynamic Huffman Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Example • Ordering is

  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)

More Related