Download presentation

Presentation is loading. Please wait.

Published byNatalie Hamlin Modified about 1 year 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: a3 a5 a1 a4 a2 a6 a4 a1 Variable Length: a3 a5 a1 a4 a2 a6 a4 a1 SymbolsFixed LengthVariable Length a1a a2a a3a a4a a5a a6a

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

5
Huffman code introduce a Huffman tree CharFreqCode space7111 a4010 e4000 f31101 h21010 i21000 m20111 n20010 s21011 t20110 l o p r u x

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 X

10
Add the value

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)

12

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google