Huffman Coding Yancy Vance Paredes. Outline Background Motivation Huffman Algorithm Sample Implementation Running Time Analysis Proof of Correctness Application.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

CREATING a HUFFMAN CODE EVERY EGG IS GREEN E ///// V/V/ R // Y/Y/ I/I/ S/S/ N/N/ Sp /// V/V/ Y/Y/ I/I/ S/S/ N/N/ R // Sp /// G /// E /////
Introduction to Computer Science 2 Lecture 7: Extended binary trees
Prof. Sin-Min Lee Department of Computer Science
Greedy Algorithms Amihood Amir Bar-Ilan University.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture3.
Huffman Encoding Dr. Bernard Chen Ph.D. University of Central Arkansas.
Greedy Algorithms (Huffman Coding)
CS38 Introduction to Algorithms Lecture 5 April 15, 2014.
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.
Association Clusters Definition The frequency of a stem in a document,, is referred to as. Let be an association matrix with rows and columns, where. Let.
1 Assignment 2: (Due at 10:30 a.m on Friday of Week 10) Question 1 (Given in Tutorial 5) Question 2 (Given in Tutorial 7) If you do Question 1 only, you.
© 2004 Goodrich, Tamassia Greedy Method and Compression1 The Greedy Method and Text Compression.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
© 2004 Goodrich, Tamassia Greedy Method and Compression1 The Greedy Method and Text Compression.
A Data Compression Algorithm: Huffman Compression
Lecture 6: Greedy Algorithms I Shang-Hua Teng. Optimization Problems A problem that may have many feasible solutions. Each solution has a value In maximization.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 5. Greedy Algorithms - 1 Greedy.
Data Structures – LECTURE 10 Huffman coding
Chapter 9: Huffman Codes
Greedy Algorithms CSE 331 Section 2 James Daly. Reminders Exam 2 next week Thursday, April 9th Covers heaps to spanning trees Greedy algorithms (today)
Greedy Algorithms Huffman Coding
16.Greedy algorithms Hsu, Lih-Hsing. Computer Theory Lab. Chapter 16P An activity-selection problem Suppose we have a set S = {a 1, a 2,..., a.
Data Compression Basics & Huffman Coding
Data Compression Gabriel Laden CS146 – Dr. Sin-Min Lee Spring 2004.
Data Structures and Algorithms Huffman compression: An Application of Binary Trees and Priority Queues.
Algorithm Design & Analysis – CS632 Group Project Group Members Bijay Nepal James Hansen-Quartey Winter
Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2004 Simonas Šaltenis E1-215b
Data Compression1 File Compression Huffman Tries ABRACADABRA
Huffman Encoding Veronica Morales.
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.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 5: Advanced Design Techniques.
Huffman Coding. Huffman codes can be used to compress information –Like WinZip – although WinZip doesn’t use the Huffman algorithm –JPEGs do use Huffman.
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Greedy Algorithms CSc 4520/6520 Fall 2013 Problems Considered Activity Selection Problem Knapsack Problem – 0 – 1 Knapsack – Fractional Knapsack Huffman.
Huffman Codes Juan A. Rodriguez CS 326 5/13/2003.
Bahareh Sarrafzadeh 6111 Fall 2009
Greedy Algorithms.
Huffman Codes. Overview  Huffman codes: compressing data (savings of 20% to 90%)  Huffman’s greedy algorithm uses a table of the frequencies of occurrence.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 5. Greedy Algorithms - 1 Greedy.
Huffman Encoding and Decoding Sarker Tanveer Ahmed Rumee ( ) Md. Abdus Salam ( )
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
D ESIGN & A NALYSIS OF A LGORITHM 12 – H UFFMAN C ODING Informatics Department Parahyangan Catholic University.
CS6045: Advanced Algorithms Greedy Algorithms. Main Concept –Divide the problem into multiple steps (sub-problems) –For each step take the best choice.
CSCI 58000, Algorithm Design, Analysis & Implementation Lecture 12 Greedy Algorithms (Chapter 16)
Design & Analysis of Algorithm Huffman Coding
HUFFMAN CODES.
CSC317 Greedy algorithms; Two main properties:
Tries 07/28/16 11:04 Text Compression
Assignment 6: Huffman Code Generation
The Greedy Method and Text Compression
The Greedy Method and Text Compression
Greedy Algorithm.
Heaps, Priority Queues, Compression
Chapter 9: Huffman Codes
Huffman Coding.
Algorithms (2IL15) – Lecture 2
Advanced Algorithms Analysis and Design
Greedy Algorithms Many optimization problems can be solved more quickly using a greedy approach The basic principle is that local optimal decisions may.
Huffman Coding CSE 373 Data Structures.
Chapter 16: Greedy algorithms Ming-Te Chi
Data Structure and Algorithms
Chapter 16: Greedy algorithms Ming-Te Chi
Podcast Ch23d Title: Huffman Compression
Lecture 2: 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
Analysis of Algorithms CS 477/677
Presentation transcript:

Huffman Coding Yancy Vance Paredes

Outline Background Motivation Huffman Algorithm Sample Implementation Running Time Analysis Proof of Correctness Application

Background Lossless compression where around 20% to 90% of savings in space Developed by David A. Huffman Published in 1952

Motivation /1 Let’s say we want to store the string: go go gophers (13 characters) How do we usually do it? – ASCII – 7 bits + 1 more bit 13 * 8 bits = 104 bits – Reduce it? 8 unique characters: g, o, p, h, e, r, s, space Instead of 8 bits, we can lower it to 3 bits 13 * 3 bits = 39 bits We saved 65 bits!

Motivation /2 What if we lessen the number of bits for frequent characters? CharacterFrequencyCodeTotal Bits g3006 o3016 p11003 h r e s Space21116

Motivation /3 The total number of bits used is lowered to 37 – Prefix Code Easy to encode and decode

Motivation /4 How do we decode? – 0 means go LEFT – 1 means go RIGHT How to decode the following?

How to Decode? CharacterCode g00 o01 p100 h1010 r1011 e1100 s1101 Space111

Huffman Algorithm A greedy algorithm Constructs an optimal prefix code – Huffman code HUFFMAN(C) n = |C| Q = C for i = 1 to n-1 allocate a new node z z.left = x = EXTRACT_MIN(Q) z.right = y = EXTRACT_MIN(Q) z.freq = x.freq + y.freq INSERT(Q,z) return EXTRACT_MIN(Q)

Sample Implementation See program demo

Running Time Analysis Assume that Q is implemented as a min heap (priority queue) Building the Q takes O(n) The for loop executes n-1 times – The heap operations contribute O(lg n) – Thus, the loop contributes O(n lg n) – Total running time is O(n lg n)!

Proof of Correctness /1 Show that the problem of determining an optimal prefix code exhibits the following properties: – Greedy choice – Optimal substructure

Proof of Correctness /2 To compute the cost of a tree:

Proof of Correctness /3 Greedy choice

Proof of Correctness /4 Optimal substructure

Application Commonly used as the back-end of some multimedia codecs – JPEG, MP3

Summary Background Motivation Huffman Algorithm Sample Implementation Running Time Analysis Proof of Correctness Application

References Chapter 13: Greedy Algorithm