Problem: Huffman Coding Def: binary character code = assignment of binary strings to characters e.g. ASCII code A = 01000001 B = 01000010 C = 01000011.

Slides:



Advertisements
Similar presentations
EE 4780 Huffman Coding Example. Bahadir K. Gunturk2 Huffman Coding Example Suppose X is a source producing symbols; the symbols comes from the alphabet.
Advertisements

Lecture 3: Source Coding Theory TSBK01 Image Coding and Data Compression Jörgen Ahlberg Div. of Sensor Technology Swedish Defence Research Agency (FOI)
Greedy Algorithms Amihood Amir Bar-Ilan University.
Huffman Encoding Dr. Bernard Chen Ph.D. University of Central Arkansas.
Greedy Algorithms (Huffman Coding)
Data Compressor---Huffman Encoding and Decoding. Huffman Encoding Compression Typically, in files and messages, Each character requires 1 byte or 8 bits.
T(n) = 4 T(n/3) +  (n). T(n) = 2 T(n/2) +  (n)
1 Huffman Codes. 2 Introduction Huffman codes are a very effective technique for compressing data; savings of 20% to 90% are typical, depending on the.
Lecture 6: Huffman Code Thinh Nguyen Oregon State University.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
A Data Compression Algorithm: Huffman Compression
DL Compression – Beeri/Feitelson1 Compression דחיסה Introduction Information theory Text compression IL compression.
Chapter 9 Greedy Technique Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Data Structures – LECTURE 10 Huffman coding
Chapter 9: Huffman Codes
CSE 326 Huffman coding Richard Anderson. Coding theory Conversion, Encryption, Compression Binary coding Variable length coding A B C D E F.
Variable-Length Codes: Huffman Codes
Greedy Algorithms Huffman Coding
Data Compression Gabriel Laden CS146 – Dr. Sin-Min Lee Spring 2004.
Basics of Compression Goals: to understand how image/audio/video signals are compressed to save storage and increase transmission efficiency to understand.
Huffman Coding Vida Movahedi October Contents A simple example Definitions Huffman Coding Algorithm Image Compression.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2004 Simonas Šaltenis E1-215b
Source Coding-Compression
Huffman Codes. Encoding messages  Encode a message composed of a string of characters  Codes used by computer systems  ASCII uses 8 bits per character.
Data Compression1 File Compression Huffman Tries ABRACADABRA
1 Analysis of Algorithms Chapter - 08 Data Compression.
Lecture Objectives  To learn how to use a Huffman tree to encode characters using fewer bytes than ASCII or Unicode, resulting in smaller files and reduced.
Data Structures Week 6: Assignment #2 Problem
 Greedy Algorithms. Greedy Algorithm  Greedy Algorithm - Makes locally optimal choice at each stage. - For optimization problems.  If the local optimum.
Huffman Coding Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
ALGORITHMS FOR ISNE DR. KENNETH COSH WEEK 13.
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Greedy Algorithms Input: Output: Objective: - make decisions “greedily”, previous decisions are never reconsidered Optimization problems.
Huffman coding Content 1 Encoding and decoding messages Fixed-length coding Variable-length coding 2 Huffman coding.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 9 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Dynamic programming vs Greedy algo – con’t Input: Output: Objective: a number W and a set of n items, the i-th item has a weight w i and a cost c i a subset.
Huffman Codes Juan A. Rodriguez CS 326 5/13/2003.
CPS 100, Spring Huffman Coding l D.A Huffman in early 1950’s l Before compressing data, analyze the input stream l Represent data using variable.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
Bahareh Sarrafzadeh 6111 Fall 2009
Lossless Decomposition and Huffman Codes Sophia Soohoo CS 157B.
Huffman Codes. Overview  Huffman codes: compressing data (savings of 20% to 90%)  Huffman’s greedy algorithm uses a table of the frequencies of occurrence.
1 Data Compression Hae-sun Jung CS146 Dr. Sin-Min Lee Spring 2004.
1 Huffman Codes. 2 ASCII use same size encoding for all characters. Variable length codes can produce shorter messages than fixed length codes Huffman.
Huffman encoding.
Greedy algorithms 2 David Kauchak cs302 Spring 2012.
SEAC-2 J.Teuhola Coding-Theoretic Foundations Source alphabet S  Target alphabet {0, 1} Categories of source encoding: 1. Codebook methods:
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
Ch4. Zero-Error Data Compression Yuan Luo. Content  Ch4. Zero-Error Data Compression  4.1 The Entropy Bound  4.2 Prefix Codes  Definition and.
CSCI 58000, Algorithm Design, Analysis & Implementation Lecture 12 Greedy Algorithms (Chapter 16)
Huffman Codes ASCII is a fixed length 7 bit code that uses the same number of bits to define each character regardless of how frequently it occurs. Huffman.
EE465: Introduction to Digital Image Processing
Assignment 6: Huffman Code Generation
Increasing Information per Bit
Greedy Technique.
Proving the Correctness of Huffman’s Algorithm
The Greedy Method and Text Compression
The Huffman Algorithm We use Huffman algorithm to encode a long message as a long bit string - by assigning a bit string code to each symbol of the alphabet.
Chapter 9: Huffman Codes
Chapter 16: Greedy Algorithms
Advanced Algorithms Analysis and Design
Trees Addenda.
Data Structure and Algorithms
CSE 326 Huffman coding Richard Anderson.
Algorithms CSCI 235, Spring 2019 Lecture 30 More Greedy Algorithms
Huffman Coding Greedy Algorithm
Huffman codes Binary character code: each character is represented by a unique binary string. A data file can be coded in two ways: a b c d e f frequency(%)
Algorithms CSCI 235, Spring 2019 Lecture 31 Huffman Codes
Proving the Correctness of Huffman’s Algorithm
Presentation transcript:

Problem: Huffman Coding Def: binary character code = assignment of binary strings to characters e.g. ASCII code A = B = C = … fixed-length code How to decode: ?

Problem: Huffman Coding e.g. code A = 0 B = 10 C = 11 … variable-length code How to decode: ? Def: binary character code = assignment of binary strings to characters

Problem: Huffman Coding e.g. code A = 0 B = 10 C = 11 … How to decode: ? Def: A code is prefix-free if no codeword is a prefix of another codeword. variable-length code Def: binary character code = assignment of binary strings to characters

Problem: Huffman Coding Def: A code is prefix-free if no codeword is a prefix of another codeword. variable-length code Def: binary character code = assignment of binary strings to characters e.g. another code A = 1 B = 10 C = 11 … How to decode: ?

Problem: Huffman Coding Def: Huffman coding is an optimal prefix-free code. E % A8.4966% R7.5809% I7.5448% O7.1635% T6.9509% N6.6544% S5.7351% L5.4893% C4.5388% U3.6308% D3.3844% P3.1671% M3.0129% H3.0034% G2.4705% B2.0720% F1.8121% Y1.7779% W1.2899% K1.1016% V1.0074% X0.2902% Z0.2722% J0.1965% Q0.1962% Optimization problems - Input: - Output: - Objective:

an alphabet with frequencies a prefix-free code minimize expected number of bits per character Problem: Huffman Coding Def: Huffman coding is an optimal prefix-free code. E % A8.4966% R7.5809% I7.5448% O7.1635% T6.9509% N6.6544% S5.7351% L5.4893% C4.5388% U3.6308% D3.3844% P3.1671% M3.0129% H3.0034% G2.4705% B2.0720% F1.8121% Y1.7779% W1.2899% K1.1016% V1.0074% X0.2902% Z0.2722% J0.1965% Q0.1962% Huffman coding - Input: - Output: - Objective:

Problem: Huffman Coding A60% B20% C10% D10% an alphabet with frequencies a prefix-free code minimize expected number of bits per character Huffman coding - Input: - Output: - Objective: Example:Is fixed-width coding optimal ?

Problem: Huffman Coding A60% B20% C10% D10% an alphabet with frequencies a prefix-free code minimize expected number of bits per character Huffman coding - Input: - Output: - Objective: Example:Is fixed-width coding optimal ? NO, exists a prefix-free code using 1.6 bits per character !

Problem: Huffman Coding A60% B20% C10% D10% an alphabet with frequencies a prefix-free code minimize expected number of bits per character Huffman coding - Input: - Output: - Objective: Example:Is fixed-width coding optimal ? NO, exists a prefix-free code using 1.6 bits per character !

Problem: Huffman Coding an alphabet with frequencies a prefix-free code minimize expected number of bits per character Huffman coding - Input: - Output: - Objective: Huffman ( [a 1,f 1 ],[a 2,f 2 ],…,[a n,f n ]) 1. if n=1 then 2. code[a 1 ]  “” 3. else 4. let f i,f j be the 2 smallest f’s 5. Huffman ( [a i,f i +f j ],[a 1,f 1 ],…,[a n,f n ] ) omits a i,a j 6. code[a j ]  code[a i ] + “0” 7. code[a i ]  code[a i ] + “1”

Problem: Huffman Coding Let x,y be the symbols with frequencies f x > f y. Then in an optimal prefix code length(C x )  length(C y ). Lemma 1:

Problem: Huffman Coding Let x,y be the symbols with frequencies f x > f y. Then in an optimal prefix code length(C x )  length(C y ). Lemma 1: If w is a longest codeword in an optimal code then there exists another codeword of the same length. Lemma 2:

Problem: Huffman Coding Let x,y be the symbols with frequencies f x > f y. Then in an optimal prefix code length(C x )  length(C y ). Lemma 1: Let x,y be the symbols with the smallest frequencies. Then there exists an optimal prefix code such that the codewords for x and y differ only in the last bit. Lemma 3: If w is a longest codeword in an optimal code then there exists another codeword of the same length. Lemma 2:

Problem: Huffman Coding Let x,y be the symbols with frequencies f x > f y. Then in an optimal prefix code length(C x )  length(C y ). Lemma 1: Let x,y be the symbols with the smallest frequencies. Then there exists an optimal prefix code such that the codewords for x and y differ only in the last bit. Lemma 3: The prefix code output by the Huffman algorithm is optimal. Theorem: If w is a longest codeword in an optimal code then there exists another codeword of the same length. Lemma 2: