lec3 - Lecture 3 Time and space cost analysis of Huffman...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 1 of 45 CSE 100, UCSD: LEC 3 Lecture 3 Time and space cost analysis of Huffman coding Huffman coding tree implementation issues Priority queues and priority queue implementations Heaps Dynamic data and array representations for Huffman trees Reading: Weiss Ch. 6, Ch. 10.1.2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Page 2 of 45 CSE 100, UCSD: LEC 3 Huffman code trees Last time, we discussed the Huffman coding algorithm The Huffman algorithm constructs a tree (a binary trie) which represents a code This tree is used to code items from the input; the output is a sequence of bits An identical tree must be used to decode that sequence of bits, to get back the original input that was coded! We will look at some issues in implementing a Huffman code tree
Background image of page 2
Page 3 of 45 CSE 100, UCSD: LEC 3 Basic properties of a Huffman code tree Suppose there are N different symbols in the input sequence (some of them may appear more than once) For example, the input sequence THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG has length 43, and contains 27 different symbols: The capital letters A-Z, and space The Huffman trie-construction algorithm starts with a forest of N one-node trees, and then, while there is more than one tree in the forest: removes two trees from the forest, makes them the left and right subtrees of a new parent node, and returns the new tree to the forest The result is a “full” binary tree: every non-leaf node has exactly 2 children (why?!) Questions: in the resulting tree as functions of N: How many leaf nodes are there? _________ How many internal (non-leaf) nodes are there? _________ So, how many nodes in the code tree? __________
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Page 4 of 45 CSE 100, UCSD: LEC 3 Coding with a Huffman tree Suppose you have a Huffman coding tree like this: ... and you want to code the letter A The code for letter A is the sequence of bits labeling edges on the path from the root of the tree to the leaf containing A How to find that path? A BCG H 1 1 1 1 0 0 0 0
Background image of page 4
Page 5 of 45 CSE 100, UCSD: LEC 3 Coding with a Huffman tree, cont’d A not very good way to do it is to start at the root, and try to find a path to the leaf containing A (You could do that, but worst case you would have to traverse the entire tree before finally finding the leaf you want, taking (N) steps) A better way: start at the leaf containing A, follow the (unique, since in a tree every non-root node has a unique parent) path to the root of the tree keeping track of the bits on the path. .. and then reverse that sequence of bits A clever way to do that uses recursion To see how to do that, we will take a short detour into linked lists. ..
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Page 6 of 45 CSE 100, UCSD: LEC 3 Traversing a data structure A data structure contains elements, which contain data Traversing a data structure means: “visiting” or “touching” the elements of the structure, and doing something with the data (Traversing is also sometimes called iterating over the data structure)
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 45

lec3 - Lecture 3 Time and space cost analysis of Huffman...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online