Download presentation

Presentation is loading. Please wait.

Published byNatalie Hamlin Modified over 2 years ago

1
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 9

2
Huffman Code Fixed Length Coding and Variable Length Coding Principle of Huffman Coding Huffman Tree Definition of Heaps Complete Binary Heap

3
Fixed Length Coding and Variable Length Coding Decoding Fixed Length: 010100000011001101011000 a3 a5 a1 a4 a2 a6 a4 a1 Variable Length: 0001001000101111001010 a3 a5 a1 a4 a2 a6 a4 a1 SymbolsFixed LengthVariable Length a1a1 000010 a2a2 001011 a3a3 010000 a4a4 011001 a5a5 10010 a6a6 10111

4
Prefix-Free None of the code words are the refix of other code words Not Prefix Free Example: a1 01 a2 011 … 011011011 a1… 011011011 a2…

5
Huffman code introduce a Huffman tree CharFreqCode space7111 a4010 e4000 f31101 h21010 i21000 m20111 n20010 s21011 t20110 l111001 o100110 p110011 r111000 u100111 x110010 0 1 0 00 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 11 1 1 1 1 1

6
Generate Huffman Tree from bottom to top Calculate minimum subtree Incursive process until all nodes are added Generate Huffman Code from top to bottom To achieve Prefix Free

7
A heap is a specialized tree that satisfies the heap property: if B is a child node of A, then key(A) ≥ key(B). ▪ This implies that an element with the greatest key is always in the root node, and so such a heap is sometimes called a max-heap. Alternatively, if the comparison is reversed, the smallest element is always in the root node, which results in a min-heap.

8
The shape property: the tree is a complete binary tree The heap property: each node is smaller than or equal(for min-heap) to each of its children Fig 1.a complete binary min heap

9
Often stored as arrays of entries by level- order traversal of the tree 2 53 96 17108 114 X25396 417108

10
Add the value 1 2 53 96 17108 114 1 6 1 1 5 1 2

11
Binary HeapSorted ListUnsorted List min()O(1) O(n) Insert() Worst-caseO(log n)O(n)O(1) Best-caseO(1) removeMin() Worst-caseO(log n)O(1)O(n) Best-caseO(1) O(n)

Similar presentations

Presentation is loading. Please wait....

OK

Greedy Algorithms Amihood Amir Bar-Ilan University.

Greedy Algorithms Amihood Amir Bar-Ilan University.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on types of business communication Ppt on viruses and bacteria worksheet Ppt on history of atomic model Ppt on javascript events status Ppt on electric power steering Ppt on x ray crystallography Ppt on trial and error factoring Ppt on cash flow analysis Can i run ppt on ipad Ppt on building construction process