Huffman Coding The most for the least. Design Goals Encode messages parsimoniously No character code can be the prefix for another.

Slides:



Advertisements
Similar presentations
Functional Programming Lecture 15 - Case Study: Huffman Codes.
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 /////
Algorithm Design Techniques: Greedy Algorithms. Introduction Algorithm Design Techniques –Design of algorithms –Algorithms commonly used to solve problems.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Greedy Algorithms Amihood Amir Bar-Ilan University.
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.
Lecture04 Data Compression.
Compression & Huffman Codes
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Optimal Merging Of Runs
A Data Compression Algorithm: Huffman Compression
Compression & Huffman Codes Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 04 / 29 / 2009 Instructor: Michael Eckmann.
Data Structures – LECTURE 10 Huffman coding
Chapter 9: Huffman Codes
CS 206 Introduction to Computer Science II 12 / 10 / 2008 Instructor: Michael Eckmann.
Data Compression and Huffman Trees (HW 4) Data Structures Fall 2008 Modified by Eugene Weinstein.
Huffman Codes Message consisting of five characters: a, b, c, d,e
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
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
Huffman Encoding Veronica Morales.
Graph Theory in Computer Science Greg Stoll November 22, 2008.
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.
CS-2852 Data Structures LECTURE 13B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Data Structures Week 6: Assignment #2 Problem
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.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
Huffman coding Content 1 Encoding and decoding messages Fixed-length coding Variable-length coding 2 Huffman coding.
Huffman Code and Data Decomposition Pranav Shah CS157B.
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.
CS654: Digital Image Analysis Lecture 34: Different Coding Techniques.
Huffman’s Algorithm 11/02/ Weighted 2-tree A weighted 2-tree T is an extended binary tree with n external nodes and each of the external nodes is.
Foundation of Computing Systems
1 Algorithms CSCI 235, Fall 2015 Lecture 30 More Greedy Algorithms.
1Computer Sciences Department. 2 Advanced Design and Analysis Techniques TUTORIAL 7.
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.
Lecture 12 Huffman Algorithm. In computer science and information theory, a Huffman code is a particular type of optimal prefix code that is commonly.
Huffman encoding.
Compression and Huffman Coding. Compression Reducing the memory required to store some information. Lossless compression vs lossy compression Lossless.
Design & Analysis of Algorithm Huffman Coding
Tries 07/28/16 11:04 Text Compression
Assignment 6: Huffman Code Generation
Tries 5/27/2018 3:08 AM Tries Tries.
Chapter 5 : Trees.
Greedy Technique.
Chapter 5. Greedy Algorithms
Binary search tree. Removing a node
Proving the Correctness of Huffman’s Algorithm
Greedy Algorithm.
Data Encoding Characters.
Optimal Merging Of Runs
Digital Search Trees & Binary Tries
Data Compression If you’ve ever sent a large file to a friend, you may have compressed it into a zip archive like the one on this slide before doing so.
Chapter 9: Huffman Codes
Chapter 16: Greedy Algorithms
Optimal Merging Of Runs
Math 221 Huffman Codes.
Huffman Encoding Huffman code is method for the compression for standard text documents. It makes use of a binary tree to develop codes of varying lengths.
Trees Addenda.
Data Structure and Algorithms
Tries 2/23/2019 8:29 AM Tries 2/23/2019 8:29 AM Tries.
Podcast Ch23d Title: Huffman Compression
Algorithms CSCI 235, Spring 2019 Lecture 30 More Greedy Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 31 Huffman Codes
Proving the Correctness of Huffman’s Algorithm
Presentation transcript:

Huffman Coding The most for the least

Design Goals Encode messages parsimoniously No character code can be the prefix for another

Requirements Message statistics Data structures to create and store new codes

Conventional Encoding Schemes Fixed length codes – E.g., Unicode, ASCII, rgb Sample data Optimal code length (in bits) is given by the entropy E: FreqLog2(Freq)-Product A B C D E Entropy=>

Huffman Algorithm While (two or more trees in the Forest) – Find the two least weight trees i and j – Create a code Tree node whose left child is the root of tree i and right child is the root of tree j – Join the two least weight trees and replace tree i – Delete tree j

Graphical Solution (Step 1) A 0.13 B 0.27 C 0.35 D 0.17 E E 0.08 A 0.13 B 0.27 C 0.35 D 0.17

Graphical Solution (Step 2) B 0.27 C 0.35 D 0.17 B 0.27 C 0.35 D E 0.08 A E 0.08 A 0.13

Graphical Solution (Step 3) B 0.27 C 0.35 D D B 0.27 C E 0.08 A E 0.08 A 0.13

Graphical Solution (Step 4) D E 0.08 A D B 0.27 C B 0.27 C E 0.08 A 0.13

Interpreting the Code B 0.27 C 0.35 D E 0.08 A Symb ol CodeLengthFreqProd A B C D E Avg.2.21

Data Structures ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot A B C D E 55000

Step 1 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot A B C D E 55000

Step 2 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot A B C D E

Step 3 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot A B C D E

Step 4 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot A B C D E

Step 5 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot 1191A B C D E