in Algorithms
2,792 views
1 vote
1 vote
what is Space complexity of Huffman coding?
in Algorithms
2.8k views

2 Answers

2 votes
2 votes
Best answer

If we have n symble then  we need to store each Symble in Array so 

Space complexity = O(n)

selected by

4 Comments

Thank you for such a detailed explanation.  I understood the concept but what about Huffman coding's space complexity? Is it O(n) or O(1). According to my understanding, we need n extra space to keep track of frequencies of the characters. What is your opinion on that.
0
0

@Akhilesh ,

I have given the link of University of Texas where it is mentioned that :-

We often speak of "extra" memory needed, not counting the memory needed to store the input itself.

So, we should not have to consider the input size to find the space complexity of an algorithm.

@Akash ,it should be O(n) which you have already mentioned because we have to store frequencies of characters from the input file seperately in the array.

3
3
Does the input will not contain the elements array and its frequency as its input?
0
0
0 votes
0 votes
To obtain Huffman coding we use data structure called min heap. At the initial phase all the nodes has to be present in heap(satisfying min-heap property).

If there are n elements in tree then space complexity will be O(n) which is extra space required.