CSL 210: Data Structures With Applications: Module3: IIIT Nagpur
CSL 210: Data Structures With Applications: Module3: IIIT Nagpur
Applications: Module3
IIIT Nagpur
Aniket Pingley
Binary Heap
• A binary heap is a complete binary tree that satis es the heap property - min
and max
• A min-heap is a binary tree such that - the data contained in each node is less
than (or equal to) the data in that node’s children
• A max-heap is a binary tree such that - the data contained in each node is
greater than (or equal to) the data in that node’s children.
fi
Binary Heap
Complete Binary Tree that satis es the heap property
fi
Array Representation for Binary Heap
A data le of 100,000 characters contains only the characters a–f, with the frequencies
indicated. If we assign each character a 3-bit codeword, we can encode the le in
300,000 bits. Using the variable-length code shown, we can encode the le in only
224,000 bits (1000 x (45x1 + 13x3 + 12x3 + 16x3 + 9x4 + 5x4)).
fi
fi
fi
Binary Tree Representation
Disregard the values at non-leaf nodes for this slide
Prefix codes
• Encoding and Decoding a pre x code is done using Binary Tree, where leaf
nodes are the input symbol characters/symbols.
fi
fi
fi
Build
Huffman
Code
Constructing Huffman Code
Step-by-step
extraction and
insertion process of
Huffman Coding