Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review GitHub Project Guide Huffman Coding

Similar presentations


Presentation on theme: "Review GitHub Project Guide Huffman Coding"— Presentation transcript:

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

2 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

3 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

4

5

6

7

8 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?

9 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

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

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

12 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();

13 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();

14 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

15 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

16 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

17 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

18 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

19 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

20 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

21 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

22 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

23 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

24 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

25 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

26 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

27 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

28 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

29 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

30 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

31 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

32 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; }

33 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; }

34 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; }

35 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

36 An Introduction to Huffman Coding
March 21, 2000 Get the code book Char Code E i y l k space 011 e 10 r s n a E 1 i sp 4 e 8 2 y l k . r s n a 6 10 16 26 Mike Scott

37 Generate the result Eerie eyes seen near lake.

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


Download ppt "Review GitHub Project Guide Huffman Coding"

Similar presentations


Ads by Google