1.8 Huffman compression Flashcards

1
Q

What is the basic idea of compression?

A

To encode frequently-occurring items using fewer bits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How many bits does uncompressed ASCII characters use?

A

8 bits each.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Compress the text ‘AAA Go’ using Huffman coding.

A

0 0 0 10 110 111.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many bits does the compressed version of ‘AAA Go’ use?

A

11 bits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the dictionary in Huffman compression do?

A

It assigns shorter codes to frequent items.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the compressed code for the ASCII string ‘00000000 00000000 11111111 00000100’ using the given dictionary?

A

00 00 01 111.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Is any code in the provided dictionary a prefix of another code?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the output for decompressing the code ‘00 01 00’?

A

00000000 11111111 00000000.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a character frequency table?

A

A table that contains each distinct character from the input string and each character’s number of occurrences.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the pseudocode ‘BuildCharacterFrequencyTable’ do?

A

It builds a frequency table for characters in an input string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What character frequency is assigned to the letter ‘A’ in the string ‘APPLES AND BANANAS’?

A

5.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Huffman coding?

A

A common compression technique that assigns fewer bits to frequent items using a binary tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the first step in Huffman coding?

A

Determine the frequencies of each item.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the compressed output for the text ‘aabbbaaccd’ using Huffman coding?

A

0 0 10 10 10 0 0 110 110 111.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How is the encoding for each leaf node obtained in Huffman coding?

A

By traversing from the top node to the leaf, appending 0 for left branches and 1 for right branches.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fill in the blank: Prior to compression, a _______ must be built for an input string.

A

character frequency table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What occurs when a character appears for the first time in the frequency table?

A

Its frequency is set to 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What happens to the frequency of a character when it appears again in the frequency table?

A

The existing frequency is incremented.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the total frequency count of the string ‘seems he fleed’ for the letter ‘e’?

A

3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

True or False: In Huffman coding, the merging of nodes continues until only one node exists.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the first merge in Huffman coding for the frequencies D: 3 and E: 3?

A

D and E: 6

This merge yields the smallest sum: 3 + 3 = 6.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the second merge in Huffman coding after merging D and E?

A

DE and B: 10

DE is 6 (from the first merge). B is 4. So 6 + 4 = 10.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the third merge in Huffman coding after DE and B?

A

DEB and C: 50

DEB is 10 (from the second merge). C is 40. So 10 + 40 = 50.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the fourth merge in Huffman coding after DEB and C?

A

DEBC and A: 100

DEBC is 50 (from the third merge), and A is 50. So 50 + 50 = 100.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the fifth merge in Huffman coding?

A

None

Only one node remains: DEBCA. No more merges are possible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is the code for character A in Huffman coding?

A

0

A is one branch to the left. A left branch appends a 0 to the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is the code for character C in Huffman coding?

A

10

C is a right branch (1) and then a left branch (0), yielding 10.

28
Q

What is the code for character B in Huffman coding?

A

110

Right, right, left yields 1, 1, 0, or 110.

29
Q

What is the code for character D in Huffman coding?

A

1110

Right, right, right, left yields 1, 1, 1, 0, or 1110.

30
Q

What is the code for character E in Huffman coding?

A

1111

Right, right, right, right yields 1111.

31
Q

If 5 unique characters can each be uniquely encoded in 3 bits, how many bits are needed for a 100-character text?

A

300

100 * 3 = 300.

32
Q

For the Huffman code determined, how many bits are needed for the 100-character text with frequencies A: 1, C: 2, B: 3, D: 4, E: 4?

A

166

501 + 402 + 43 + 34 + 3*4 = 166.

33
Q

What data members do leaf nodes in a Huffman tree have?

A

A character and an integer frequency.

Leaf nodes represent individual characters and their frequencies.

34
Q

What data members do internal nodes in a Huffman tree have?

A

Left and right child nodes, and an integer frequency value.

Internal nodes represent the sum of the frequencies of their child nodes.

35
Q

What is the first step in building a Huffman tree?

A

Build the frequency table.

This table lists the frequency of each character in the input string.

36
Q

How are parent nodes created in a Huffman tree?

A

By dequeuing the two lowest-priority nodes and creating a new parent node.

The parent’s frequency is the sum of the child frequencies.

37
Q

What does the function HuffmanGetCodes do?

A

It builds Huffman codes for each character.

The codes are generated by tracing a path from the root to each character’s leaf node.

38
Q

What is the output of the HuffmanGetCodes function when called on a tree with root node 7?

A

A: 0, S: 101, B: 100, N: 11

The output is a dictionary mapping characters to their respective Huffman codes.

39
Q

How many entries does the character frequency table have for the string ‘zyBooks’?

A

6

One entry exists per distinct character.

40
Q

What is the frequency of the parent node for nodes B and k in the priority queue?

A

2

The parent’s frequency is the sum of the child frequencies, which are both 1.

41
Q

What is the purpose of the HuffmanGetCodes function?

A

To generate Huffman codes for each character based on the tree structure

The codes are built recursively; left branches add a 0, and right branches add a 1.

42
Q

What is the Huffman code for character A in the tree built from ‘BANANAS’?

A

0

A’s leaf node is reached via a left branch from the root.

43
Q

What is the Huffman code for character B in the tree built from ‘BANANAS’?

A

100

B’s code is determined by traversing left and right branches from the root.

44
Q

What is the Huffman code for character S in the tree built from ‘BANANAS’?

A

101

S is reached by moving right from node 4 then left.

45
Q

What is the Huffman code for character N in the tree built from ‘BANANAS’?

A

11

N is reached by following the right branches after reaching node 4.

46
Q

What is the maximum length of a Huffman code in the tree built from ‘BANANAS’?

A

4

This length corresponds to the longest path from the root to a leaf.

47
Q

What is the first step in compressing data using Huffman coding?

A

Obtain Huffman codes for each character

Codes are generated based on the frequency of characters in the input string.

48
Q

Fill in the blank: The result of HuffmanCompress function is a _______.

A

compressed binary string

The result is formed by concatenating bit codes corresponding to each character.

49
Q

What does the HuffmanDecompress function do?

A

Decompresses Huffman encoded data by tracing the tree based on bit values

It starts at the root and follows left or right based on each bit until a leaf is reached.

50
Q

What is the output of HuffmanCompress(‘BANANAS’)?

A

111 0 10 0 10 0 110

This result reflects the frequency of characters in the input string.

51
Q

True or False: Each distinct character in a Huffman tree has a unique code.

A

True

This uniqueness follows from the properties of the Huffman coding algorithm.

52
Q

What is the Huffman code for character P in the tree built from ‘APPLES AND BANANAS’?

A

011

The path to P’s leaf involves moving left and right from the root.

53
Q

What is the length of the longest Huffman code from the tree built from ‘APPLES AND BANANAS’?

A

4

The longest path from root to leaf determines the maximum code length.

54
Q

Fill in the blank: To decompress a Huffman coded string, one must start at the _______.

A

root of the Huffman tree

Traversal follows the left or right child based on the bit value until reaching a leaf.

55
Q

What character does the bit sequence ‘00’ represent in the decompression process?

A

space

The space character is represented by a specific leaf in the Huffman tree.

56
Q

What is the first step in the HuffmanDecompress function?

A

Initialize node to treeRoot and result to an empty string

57
Q

In the HuffmanDecompress function, what does the bit value determine?

A

It determines whether to go to the left or right child

58
Q

What happens when a leaf node is reached in the HuffmanDecompress function?

A

The character is added to the result and the node is reset to treeRoot

59
Q

Fill in the blank: The function HuffmanDecompress takes _______ and _______ as parameters.

A

[compressedString], [treeRoot]

60
Q

What is the first decoded character from the compressed string 0111101000101 using the provided tree?

61
Q

What does the bit sequence ‘11’ correspond to in the decompression process?

A

It corresponds to the character O

62
Q

What is the second decoded character from the compressed string 0111101000101?

63
Q

What character is reached after decoding ‘100’?

64
Q

What is the complete decoded text from the sequence 0111101000101?

65
Q

True or False: The HuffmanDecompress function only processes bits until it reaches a non-leaf node.