This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Huffman Code”.
1. Which of the following algorithms is the best approach for solving Huffman codes?
a) exhaustive search
b) greedy algorithm
c) brute force algorithm
d) divide and conquer algorithm
Explanation: Greedy algorithm is the best approach for solving the Huffman codes problem since it greedily searches for an optimal solution.
2. How many printable characters does the ASCII character set consists of?
Explanation: Out of 128 characters in an ASCII set, roughly, only 100 characters are printable while the rest are non-printable.
3. Which bit is reserved as a parity bit in an ASCII set?
Explanation: In an ASCII character set, seven bits are reserved for character representation while the eighth bit is a parity bit.
4. How many bits are needed for standard encoding if the size of the character set is X?
a) log X
Explanation: If the size of the character set is X, then [log X] bits are needed for representation in a standard encoding.
5. The code length does not depend on the frequency of occurrence of characters.
Explanation: The code length depends on the frequency of occurrence of characters. The more frequent the character occurs, the less is the length of the code.
6. In Huffman coding, data in a tree always occur?
c) left sub trees
d) right sub trees
Explanation: In Huffman encoding, data is always stored at the leaves of a tree inorder to compute the codeword effectively.
Explanation: By recording the path of the node from root to leaf, the code word for character ‘a’ is found to be 011.
Explanation: By recording the path of the node from root to leaf, assigning left branch as 0 and right branch as 1, the codeword for c is 110.
9. What will be the cost of the code if character ci is at depth di and occurs at frequency fi?
Explanation: If character ci is at depth di and occurs at frequency fi, the cost of the codeword obtained is ∑fidi.
10. An optimal code will always be present in a full tree.
Explanation: An optimal tree will always have the property that all nodes are either leaves or have two children. Otherwise, nodes with one child could move up a level.
11. The type of encoding where no character code is the prefix of another character code is called?
a) optimal encoding
b) prefix encoding
c) frequency encoding
d) trie encoding
Explanation: Even if the character codes are of different lengths, the encoding where no character code is the prefix of another character code is called prefix encoding.
12. What is the running time of the Huffman encoding algorithm?
b) O(log C)
c) O(C log C)
d) O( N log C)
Explanation: If we maintain the trees in a priority queue, ordered by weight, then the running time is given by O(C log C).
13. What is the running time of the Huffman algorithm, if its implementation of the priority queue is done using linked lists?
b) O(log C)
c) O(C log C)
Explanation: If the implementation of the priority queue is done using linked lists, the running time of Huffman algorithm is O(C2).
Sanfoundry Global Education & Learning Series – Data Structures & Algorithms.
To practice all areas of Data Structures & Algorithms, here is complete set of 1000+ Multiple Choice Questions and Answers.