CS notes 11

CS notes 11 - o Make a tree in which the root is the sum of...

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

View Full Document Right Arrow Icon
Huffman Coding Monday, March 21, 2011 4:07 PM Text Compression Each character = n bits of storage space 8 bits (e.g. C): ASCII code: 0. .255 16 bits (e.g. Java): Unicode:0. .2 16 -1 8 bits=1 byte N is fixed length String of text=100 characters long Storage space=200 bytes in Unicode Text compression uses variable length codes o Idea: longer codes for less frequent characters, shorter codes for more Huffman Coding Comes up with variable length codes for chars in text, given their probabilities of occurrence Example: Chars A T W U E $ Probs .1 .1 .1 .2 .2 .3 If fixed length code is used, minimum n needed is 3 bits o 0..2 3 -1 String: ate$wet Char Binary Int A 000 0 T 001 1 W 010 2 U 011 3 E 100 4 $ 101 5 110 6 111 7 Build bottom up, starting with the leaf nodes (see assignment 3) o S: queue of single node trees, one per char, enqueued in increasing order of probabilities A T W U E $
Background image of page 1

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

View Full DocumentRight Arrow Icon
o T: Initially empty Step 1: Dequeue A and T from S
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: o Make a tree in which the root is the sum of the probabilities o S: W U E $ Can only be done if no code is the prefix of another • Huffman coding guarantees this because chars are leaf nodes Char Code A 010 T 011 W 110 U 111 E 00 $ 10 Getting the probabilities • Total # of chars=n • Scan the text: O(n) • Put in array of size n • Sort list: o Time: O(n) o Space: O(k) o Highest frequency=k o Make array of LL size k o Frequency=index o Put every char in n into k Time to build tree • # of chars=c • Basic operations 1. Make a new node: O(1) • Total= O(c) 1. Enqueue (includes probability comparison): O(1) • Total= O(c) 1. Dequeue(includes probability comparison): O(1) • Total= O(c) • How many nodes in the tree? o 2c-1 Total Time: O(n)+O(c)=O(n) Total Space: O(c) + O(k)+ O(c)= O(c+k)...
View Full Document

This note was uploaded on 02/29/2012 for the course 198 112 taught by Professor Venugopal during the Spring '09 term at Rutgers.

Page1 / 3

CS notes 11 - o Make a tree in which the root is the sum of...

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

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