lecture_07

# lecture_07 - Greedy Algorithms Huffman Encoding Dasgupta et...

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

Greedy Algorithms Huffman Encoding Dasgupta et al. 5.2 Cormen et al. 16.3

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

View Full Document
Greedy algorithms Characterization: s Build up a solution in small steps; s Each step makes a choice/decision based on a simple but probably “short-sighted” objective. ope for the best: The overall solution can satisfy the 2 s Hope for the best: The overall solution can satisfy the required global criteria. E.g. How to manage a portfolio of stocks. s Everyday: sell the stock with the biggest gain s Everyday: buy the stock with the bigger loss Long-term objective: maximum gain in the coming 10 years. E.g., MST: Prim’s algorithm, Kruskal’s algorithm
Analysis of greedy algorithms Greedy algorithms are usually simple and easy to understand. Most algorithms you invent are greedy algorithms. Greedy algorithms may not give best answers in many cases. To prove a greedy algorithm works (produces an optimal lution) is often challenging. (E.g., MST). 3 solution) is often challenging. Two approaches s Proving the greedy algorithm stays ahead any other algorithm at each step; s Exchange argument: transform an optimal solution into the solution found by the greedy algorithm without hurting the cost.

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

View Full Document
Simple data compression, Huffman codes Consider a piece of text T over an alphabet A. E.g., T = “ aabaacddad ” where A = {a,b,c,d}. We can store the text using 2 bits per character. E.g., a : 00, b :01, c :10, d : 11; “aabaacddad” takes 20 bits. Can we use less space (memory)? Yes. 4
Simple data compression, Huffman codes Consider a piece of text T over an alphabet A. E.g., T = “ aabaacddad ” where A = {a,b,c,d}. We can store the text using 2 bits per character. E.g., a : 00, b :01, c :10, d : 11; “aabaacddad” takes 20 bits. Can we use less space (memory)? Yes. ariable ngth encoding se fewer bits for characters 5 Variable-length encoding : Use fewer bits for characters that are used very often. E.g. a = 0; d = 10; b = 110; c = 111. “aabaacddad” requires 5 + 6 + 3 + 3 = 17 bits. Given a text T, we want to find the optimal encoding .

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

View Full Document
Problem definition Input: an alphabet A , and the frequency of occurrence, denoted f (a), of each character in A. E.g., f(“a”) = .5; f(“b”) = .1; f(“c”) = .1; f(“d”) =.3 Definition . An encoding (or encoding scheme) E maps each haracter “a” in A to a binary sequence. 6
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/01/2010 for the course CS 1234 taught by Professor Chan during the Spring '10 term at University of the Bío-Bío.

### Page1 / 24

lecture_07 - Greedy Algorithms Huffman Encoding Dasgupta et...

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

View Full Document
Ask a homework question - tutors are online