lec21 - Outline • Introduction the data compression •...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Outline • Introduction the data compression • Huffman compression Lecture 21, Huffman Compression p. 1 How data are stored • fixed-length code: ASCII code — the total length: number of characters × code length. • Can we do better? – For a random sequence of characters: no – For English: yes • variable-length code – Frequently used characters: shorter code – Rarely used characters: longer code • extra code for frequently used combination – For example, Lempel-Ziv compression (next week) Lecture 21, Huffman Compression p. 2 Example:abbcccaaad • Fixed-length code – a: 00; b:01; c:10; d:11 – total length: 10 × 2 = 20 bits • Variable-length code – a: 0; b: 110; c: 10; d:111 – total length: 4 × 1 + 2 × 3 + 3 × 2 + 1 × 3 = 17 bits • How to get the optimal? Huffman tree Lecture 21, Huffman Compression p. 3 Build Huffman Trees Algorithm HuffmanTree(Σ, f) Input: Characters Σ with frequencies f (c) Output: Best prefix-tree for Σ Let Q be a Min-Queue for each c ∈ Σ Create a tree T with c as the only node Q.insert(T, f (c)) // use f (c) as priority while Q contains at least two elements (T1 , x) ← Q.ExtractMin() (T2 , y ) ← Q.ExtractMin() Create a tree T with T1 and T2 as childrem Q.Insert(T, x + y ) return Q.ExtractMin() Example: seven bananas c se Frequencies: f (c) 2 2 v 1 n 3 1 b 1 a 3 Lecture 21, Huffman Compression p. 4 Huffman Tree: Remarks • Huffman tree can be built in O(n log n) time • Huffman tree have to be built in Ω(n log n) time (cs 466) • In practice, no need to store a Huffman tree, which can be built/updated online Lecture 21, Huffman Compression p. 5 ...
View Full Document

Page1 / 5

lec21 - Outline • Introduction the data compression •...

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

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