It is used to compress a file depending on the frequency of each characters. The character with highest frequency gets the smallest code. It is also called prefx coding (i.e., none of the code is a prefix of any other code). The overall idea is to reduce the size of the entire file by reducing the number of bits required.
Time complexity to create huffman_tree = O(n*log(n))
Time complexity to display codes = O(n*log(n))