lecture_07 - Greedy Algorithms Huffman Encoding Dasgupta et...

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

View Full Document Right Arrow Icon
Greedy Algorithms Huffman Encoding Dasgupta et al. 5.2 Cormen et al. 16.3
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 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 .
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
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 / 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 Right Arrow Icon
Ask a homework question - tutors are online