Assignment 6: Huffman Code Generation

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 /////
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.
Huffman Coding: An Application of Binary Trees and Priority Queues
Optimal Merging Of Runs
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.
CS 206 Introduction to Computer Science II 04 / 29 / 2009 Instructor: Michael Eckmann.
Chapter 9: Huffman Codes
CS 206 Introduction to Computer Science II 12 / 10 / 2008 Instructor: Michael Eckmann.
CSE 326 Huffman coding Richard Anderson. Coding theory Conversion, Encryption, Compression Binary coding Variable length coding A B C D E F.
Data Compression Basics & Huffman Coding
Data Compression and Huffman Trees (HW 4) Data Structures Fall 2008 Modified by Eugene Weinstein.
x x x 1 =613 Base 10 digits {0...9} Base 10 digits {0...9}
Huffman Codes Message consisting of five characters: a, b, c, d,e
Data Structures and Algorithms Huffman compression: An Application of Binary Trees and Priority Queues.
Dr. O.Bushehrian ALGORITHM DESIGN HUFFMAN CODE. Fixed length code a: 00b: 01c: 11 Given this code, if our file is ababcbbbc our encoding is
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.
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 Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
Compression.  Compression ratio: how much is the size reduced?  Symmetric/asymmetric: time difference to compress, decompress?  Lossless; lossy: any.
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.
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 Encodings Section 9.4. Data Compression: Array Representation Σ denotes an alphabet used for all strings Each element in Σ is called a character.
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.
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.
Main Index Contents 11 Main Index Contents Complete Binary Tree Example Complete Binary Tree Example Maximum and Minimum Heaps Example Maximum and Minimum.
Lossless Decomposition and Huffman Codes Sophia Soohoo CS 157B.
Huffman Coding The most for the least. Design Goals Encode messages parsimoniously No character code can be the prefix for another.
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.
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
HUFFMAN CODES.
COMP261 Lecture 22 Data Compression 2.
Madivalappagouda Patil
ISNE101 – Introduction to Information Systems and Network Engineering
The Greedy Method and Text Compression
Optimal Merging Of Runs
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 8 – Binary Search Tree
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
Optimal Merging Of Runs
Huffman Coding.
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.
Chapter 11 Data Compression
Huffman Coding CSE 373 Data Structures.
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.
Data Structure and Algorithms
CSE 326 Huffman coding Richard Anderson.
File Compression Even though disks have gotten bigger, we are still running short on disk space A common technique is to compress files so that they take.
Data Compression.
Podcast Ch23d Title: Huffman Compression
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
Presentation transcript:

Assignment 6: Huffman Code Generation Andy Wang Data Structures, Algorithms, and Generic Programming

Huffman Code Commonly used in compression schemes Idea: Use variable-length code words Length of the word inversely proportional to the frequency of its occurrences

ASCII Encoding TALLAHASSEE ASCII values A 0100 0001 E 0100 0101

ASCII Encoding TALLAHASSEE 0101 0100 0100 0001 0100 1100 0100 1100 0100 0001 0100 1000 0100 0001 0101 0011 0101 0011 0100 0101 0100 0101 8*11 = 88 bits

Huffman Encoding TALLAHASSEE A 10 E 00 H 010 L 110 S 111 T 011

Huffman Encoding TALLAHASSEE 011 10 110 110 10 010 10 111 111 00 00 28 bits

Assignment 6 Generate Huffman Code Frequency analysis Constructing the code tree Printing out the code table

Frequency Analysis TALLAHASSEE A 3 E 2 H 1 L 2 S 2 T 1

Constructing the Code Tree Create tree nodes E:2 A:3 H:1 L:2 T:1 S:2

Constructing the Code Tree Build a modified heap H:1 L:2 T:1 A:3 E:2 S:2

Constructing the Code Tree Find two nodes with the smallest counter values T:1 L:2 S:2 A:3 E:2 H:1

Constructing the Code Tree Find two nodes with the smallest counter values E:2 L:2 S:2 A:3 H:1 T:1

Constructing the Code Tree Create a parent node E:2 L:2 S:2 A:3 H:1 T:1 :2

Constructing the Code Tree Insert the parent node back to the heap E:2 L:2 S:2 H:1 T:1 :2 A:3

Constructing the Code Tree Find two nodes with the smallest counter values H:1 T:1 :2 L:2 S:2 A:3 E:2

Constructing the Code Tree Find two nodes with the smallest counter values L:2 A:3 S:2 E:2 H:1 T:1 :2

Constructing the Code Tree Create a parent node L:2 A:3 S:2 E:2 H:1 T:1 :2 :4

Constructing the Code Tree Insert the parent node back to the heap L:2 A:3 E:2 H:1 T:1 :2 :4 S:2

Constructing the Code Tree Find two nodes with the smallest counter values S:2 E:2 H:1 T:1 :2 :4 A:3 L:2

Constructing the Code Tree Find two nodes with the smallest counter values E:2 H:1 T:1 :2 :4 A:3 L:2 S:2

Constructing the Code Tree Create a parent node A:3 :4 E:2 :2 :4 H:1 T:1 L:2 S:2

Constructing the Code Tree Insert the parent node back to the heap L:2 S:2 :4 A:3 :4 E:2 :2 H:1 T:1

Constructing the Code Tree Find two nodes with the smallest counter values L:2 S:2 :4 :4 A:3 E:2 :2 H:1 T:1

Constructing the Code Tree Find two nodes with the smallest counter values E:2 H:1 T:1 :2 :4 A:3 L:2 S:2 :4

Constructing the Code Tree Create a parent node :7 :4 A:3 L:2 S:2 :4 E:2 :2 H:1 T:1

Constructing the Code Tree Insert the parent node back to the heap A:3 L:2 S:2 :4 :7 E:2 H:1 T:1 :2 :4

Constructing the Code Tree Find two nodes with the smallest counter values E:2 H:1 T:1 :2 :4 A:3 L:2 S:2 :4 :7

Constructing the Code Tree Find two nodes with the smallest counter values :4 A:3 L:2 S:2 :4 :7 E:2 :2 H:1 T:1

Constructing the Code Tree Create a parent node :11 :4 A:3 L:2 S:2 :4 :7 E:2 :2 H:1 T:1

Constructing the Code Tree Insert the parent node back to the heap :11 :4 A:3 L:2 S:2 :4 :7 E:2 :2 H:1 T:1

Code Assignment :11 1 :4 A:3 L:2 S:2 :4 :7 1 1 E:2 :2 00 1 10 1 H:1 :4 A:3 L:2 S:2 :4 :7 1 1 E:2 :2 00 1 10 1 H:1 T:1 010 011 110 111

Properties of Huffman Code Higher the frequency, shorter the code The code for one character is not the prefix for another code 00 is not a prefix for 010 00 is a prefix for 001