Review GitHub Project Guide Huffman Coding

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 /////
Lecture 4 (week 2) Source Coding and Compression
CS252: Systems Programming Ninghui Li Program Interview Questions.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture3.
Greedy Algorithms (Huffman Coding)
Lecture 10 : Huffman Encoding Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Lecture notes : courtesy.
Data Compressor---Huffman Encoding and Decoding. Huffman Encoding Compression Typically, in files and messages, Each character requires 1 byte or 8 bits.
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.
Huffman Coding: An Application of Binary Trees and Priority Queues
A Data Compression Algorithm: Huffman Compression
Data Compression and Huffman Trees (HW 4) Data Structures Fall 2008 Modified by Eugene Weinstein.
Chapter 08 Binary Trees and Binary Search Trees © John Urrutia 2013, All Rights Reserved.
Huffman code uses a different number of bits used to encode characters: it uses fewer bits to represent common characters and more bits to represent rare.
x x x 1 =613 Base 10 digits {0...9} Base 10 digits {0...9}
Data Structures and Algorithms Huffman compression: An Application of Binary Trees and Priority Queues.
Topic 20: Huffman Coding The author should gaze at Noah, and... learn, as they did in the Ark, to crowd a great deal of matter into a very small compass.
CS 46B: Introduction to Data Structures July 30 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Binary Trees A binary tree is made up of a finite set of nodes that is either empty or consists of a node called the root together with two binary trees.
Algorithm Design & Analysis – CS632 Group Project Group Members Bijay Nepal James Hansen-Quartey Winter
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.
1 Huffman Codes Drozdek Chapter Objectives You will be able to Construct an optimal variable bit length code for an alphabet with known probability.
 The amount of data we deal with is getting larger  Not only do larger files require more disk space, they take longer to transmit  Many times files.
data ordered along paths from root to leaf
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.
Priority Queues, Trees, and Huffman Encoding CS 244 This presentation requires Audio Enabled Brent M. Dingle, Ph.D. Game Design and Development Program.
Huffman Coding Yancy Vance Paredes. Outline Background Motivation Huffman Algorithm Sample Implementation Running Time Analysis Proof of Correctness Application.
Huffman Codes Juan A. Rodriguez CS 326 5/13/2003.
1 Huffman Codes Drozdek Chapter Encoding Next we will add the capability to encode a message entered as normal text. The Huffman Tree that we use.
Lossless Decomposition and Huffman Codes Sophia Soohoo CS 157B.
1 Huffman Codes. 2 ASCII use same size encoding for all characters. Variable length codes can produce shorter messages than fixed length codes Huffman.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 5. Greedy Algorithms - 1 Greedy.
Compression and Huffman Coding. Compression Reducing the memory required to store some information. Lossless compression vs lossy compression Lossless.
Advanced Pointers and Structures Pointers in structures Memory allocation Linked Lists –Stacks and queues Trees –Binary tree example.
3.3 Fundamentals of data representation
Podcast Ch23e Title: Implementing Huffman Compression
HUFFMAN CODES.
COMP261 Lecture 22 Data Compression 2.
Assignment 6: Huffman Code Generation
Madivalappagouda Patil
Data Structures and Algorithms I Day 9, 9/22/11 Heap Sort
Lecture Trees Chapter 9 of textbook 1. Concepts of trees
Heaps, Priority Queues, Compression
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.
IndexMinPQ.
Heaps and Priority Queue
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.
Huffman Compression.
Chapter 9: Huffman Codes
IndexMinPQ.
Huffman Coding.
Math 221 Huffman Codes.
Lecture 24: Priority Queues and Huffman Encoding
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.
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
Topic 20: Huffman Coding The author should gaze at Noah, and ... learn, as they did in the Ark, to crowd a great deal of matter into a very small compass.
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.
Podcast Ch23d Title: Huffman Compression
Algorithms CSCI 235, Spring 2019 Lecture 31 Huffman Codes
Tree (new ADT) Terminology: A tree is a collection of elements (nodes)
Presentation transcript:

Review GitHub Project Guide Huffman Coding Compression Review GitHub Project Guide Huffman Coding

Review GitHub Make sure you know how to clone from website Make sure you know how to submit your homework Make sure you know how to push

Using cmd find URL like https://github.com/…/…/*.git Clone command: git clone <repository> *Cloned repository should be in local git directory Add files to local: git add <filepattern> Commit: git commit –m <msg> Push: git push *push follows commit *BESURE TO PUSH *write comments

Project Guide 2 Part Notice: Questions? enumerate all good passwords determine entered passwords are good, recommend if necessary Notice: Considering what is input/output exactly before your design Considering how to test your program before your design Considering pruning rules in your design Questions?

Huffman Coding Variable bit widths coding Idea: not all encoding unit share same frequency If unit frequency is inverse proportion to bit width, can we save space? Practical consideration: encode string is large relative to the code table table is known

Eerie eyes seen near lake. Contain letters: ‘E’ ‘e’ ‘r’ ‘i’ ‘ ’ ‘y’ ‘s’ ‘n’ ‘a’ ‘r’ ‘l’ ‘k’ ‘.’ Char Freq E 1 y 1 k 1 e 8 s 2 . 1 r 2 n 2 i 1 a 2 ‘ ’ 4 l 1

Data Structure Priority Queue: lower frequency -> higher priority Node: Node{ Char letter int frequency Node Left Node right }

Huffman encoding trie private static Node buildTrie(int[] freq) { MinPQ<Node> pq = new MinPQ<Node>(); for (char ch = 0; ch < R; ++ch if (freq[ch] > 0) pq.insert(new Node(c, freq[c], null, null)); while (pq.size() > 1) { Node x=pq.delMin(); Node y=pq.delMin(); Node parent = new Node(‘\0’, x.freq + y.freq, x, y); pq.insert(parent); } return pq.delMin();

E 1 i y l k . r 2 s n a sp 4 e 8 private static Node buildTrie(int[] freq) { MinPQ<Node> pq = new MinPQ<Node>(); for (char ch = 0; ch < R; ++ch if (freq[ch] > 0) pq.insert(new Node(c, freq[c], null, null)); while (pq.size() > 1) { Node x=pq.delMin(); Node y=pq.delMin(); Node parent = new Node(‘\0’, x.freq + y.freq, x, y); pq.insert(parent); } return pq.delMin();

y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 sp 4 e 8 private static Node buildTrie(int[] freq) { MinPQ<Node> pq = new MinPQ<Node>(); for (char ch = 0; ch < R; ++ch if (freq[ch] > 0) pq.insert(new Node(c, freq[c], null, null)); while (pq.size() > 1) { Node x=pq.delMin(); Node y=pq.delMin(); Node parent = new Node(‘\0’, x.freq + y.freq, x, y); pq.insert(parent); } return pq.delMin(); 2 E 1 i 1

An Introduction to Huffman Coding March 21, 2000 y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 2 sp 4 e 8 E 1 i 1 private static Node buildTrie(int[] freq) { MinPQ<Node> pq = new MinPQ<Node>(); for (char ch = 0; ch < R; ++ch if (freq[ch] > 0) pq.insert(new Node(c, freq[c], null, null)); while (pq.size() > 1) { Node x=pq.delMin(); Node y=pq.delMin(); Node parent = new Node(‘\0’, x.freq + y.freq, x, y); pq.insert(parent); } return pq.delMin(); Mike Scott

An Introduction to Huffman Coding March 21, 2000 k 1 . 1 r 2 s 2 n 2 a 2 2 sp 4 e 8 private static Node buildTrie(int[] freq) { MinPQ<Node> pq = new MinPQ<Node>(); for (char ch = 0; ch < R; ++ch if (freq[ch] > 0) pq.insert(new Node(c, freq[c], null, null)); while (pq.size() > 1) { Node x=pq.delMin(); Node y=pq.delMin(); Node parent = new Node(‘\0’, x.freq + y.freq, x, y); pq.insert(parent); } return pq.delMin(); E 1 i 1 2 y 1 l 1 Mike Scott

An Introduction to Huffman Coding March 21, 2000 2 k 1 . 1 r 2 s 2 n 2 a 2 2 sp 4 e 8 y 1 l 1 E 1 i 1 private static Node buildTrie(int[] freq) { MinPQ<Node> pq = new MinPQ<Node>(); for (char ch = 0; ch < R; ++ch if (freq[ch] > 0) pq.insert(new Node(c, freq[c], null, null)); while (pq.size() > 1) { Node x=pq.delMin(); Node y=pq.delMin(); Node parent = new Node(‘\0’, x.freq + y.freq, x, y); pq.insert(parent); } return pq.delMin(); Mike Scott

An Introduction to Huffman Coding March 21, 2000 r 2 s 2 n 2 a 2 2 2 sp 4 e 8 y 1 l 1 E 1 i 1 private static Node buildTrie(int[] freq) { MinPQ<Node> pq = new MinPQ<Node>(); for (char ch = 0; ch < R; ++ch if (freq[ch] > 0) pq.insert(new Node(c, freq[c], null, null)); while (pq.size() > 1) { Node x=pq.delMin(); Node y=pq.delMin(); Node parent = new Node(‘\0’, x.freq + y.freq, x, y); pq.insert(parent); } return pq.delMin(); 2 k 1 . 1 Mike Scott

An Introduction to Huffman Coding March 21, 2000 r 2 s 2 n 2 a 2 2 sp 4 e 8 2 2 k 1 . 1 E 1 i 1 y 1 l 1 private static Node buildTrie(int[] freq) { MinPQ<Node> pq = new MinPQ<Node>(); for (char ch = 0; ch < R; ++ch if (freq[ch] > 0) pq.insert(new Node(c, freq[c], null, null)); while (pq.size() > 1) { Node x=pq.delMin(); Node y=pq.delMin(); Node parent = new Node(‘\0’, x.freq + y.freq, x, y); pq.insert(parent); } return pq.delMin(); Mike Scott

An Introduction to Huffman Coding March 21, 2000 n 2 a 2 2 sp 4 e 8 2 2 E 1 i 1 y 1 l 1 k 1 . 1 4 r 2 s 2 Mike Scott

An Introduction to Huffman Coding March 21, 2000 4 4 4 2 sp 4 e 8 2 2 r 2 s 2 n 2 a 2 k 1 . 1 E 1 i 1 y 1 l 1 Mike Scott

An Introduction to Huffman Coding March 21, 2000 4 4 4 e 8 2 2 r 2 s 2 n 2 a 2 E 1 i 1 y 1 l 1 6 2 sp 4 k 1 . 1 Mike Scott

An Introduction to Huffman Coding March 21, 2000 4 4 6 4 e 8 2 sp 4 2 2 r 2 s 2 n 2 a 2 k 1 . 1 E 1 i 1 y 1 l 1 What is happening to the characters with a low number of occurrences? Mike Scott

An Introduction to Huffman Coding March 21, 2000 4 6 e 8 2 2 2 sp 4 k 1 . 1 E 1 i 1 y 1 l 1 8 4 4 r 2 s 2 n 2 a 2 Mike Scott

An Introduction to Huffman Coding March 21, 2000 4 6 e 8 8 2 2 2 sp 4 4 4 k 1 . 1 E 1 i 1 y 1 l 1 r 2 s 2 n 2 a 2 Mike Scott

An Introduction to Huffman Coding March 21, 2000 8 e 8 4 4 10 r 2 s 2 n 2 a 2 4 6 2 2 2 sp 4 E 1 i 1 y 1 l 1 k 1 . 1 Mike Scott

An Introduction to Huffman Coding March 21, 2000 8 e 8 10 4 4 4 6 2 2 r 2 s 2 n 2 a 2 2 sp 4 E 1 i 1 y 1 l 1 k 1 . 1 Mike Scott

An Introduction to Huffman Coding March 21, 2000 10 16 4 6 2 2 e 8 8 2 sp 4 E 1 i 1 y 1 l 1 k 1 . 1 4 4 r 2 s 2 n 2 a 2 Mike Scott

An Introduction to Huffman Coding March 21, 2000 10 16 4 6 e 8 8 2 2 2 sp 4 4 4 E 1 i 1 y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 Mike Scott

An Introduction to Huffman Coding March 21, 2000 26 16 10 4 e 8 8 6 2 2 2 sp 4 4 4 E 1 i 1 y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 Mike Scott

An Introduction to Huffman Coding March 21, 2000 26 16 10 4 e 8 8 6 2 2 2 sp 4 4 4 E 1 i 1 y 1 l 1 k 1 . 1 r 2 s 2 n 2 a 2 Mike Scott

Priority Queue (Refer to the codes in textbook) Bottom-up reheapify (swim) implementation Private void swim(int k) { while (k > 1 && less(k/2,k) exch(k/2,k); k=k/2; }

Priority Queue (Refer to the codes in textbook) Top-down reheapify (sink) implementation Private void sink(int k) { while (2 * k <= N) int j = 2 * k; if (j < N && less(j, j + 1)) j++; if (!less(k, j)) break; exch(k, j); k = j; }

Priority Queue Private void swim(int k) { while (k > 1 && less(k/2,k) exch(k/2,k); k=k/2; } public void insert(key v) { pq[++N] = v; swim(N); } public Key delMax() Key max = pq[1]; exch(1, N--); pq[N + 1] = null; sink(1); return max; Private void sink(int k) { while (2 * k <= N) int j = 2 * k; if (j < N && less(j, j + 1)) j++; if (!less(k, j)) break; exch(k, j); k = j; }

Code Generate Perform a traversal of the tree to obtain new code words Going left is a 0 going right is a 1 code word is only completed when a leaf node is reached

An Introduction to Huffman Coding March 21, 2000 Get the code book Char Code E 0000 i 0001 y 0010 l 0011 k 0100 . 0101 space 011 e 10 r 1100 s 1101 n 1110 a 1111 E 1 i sp 4 e 8 2 y l k . r s n a 6 10 16 26 Mike Scott

Generate the result Eerie eyes seen near lake. 000010110000011001110001010110110100111 1101011111100011001111110100100101

Decode message Scan the bit string while traversal the tree: 0 go left, 1 go right end at leaf node