Encoding Flashcards

(14 cards)

1
Q

What is encoding?

A

Given a set of items n, encode them using an amount of characters

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

What is fixed length, fixed encoding?

A

The amount of bits used to encode each item is the same, and the characters used to encode is the same

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

How many bits are in a file with n-bit binary encoding?

A

n * the amount of items

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

What is variable length, fixed encoding?

A

The amount of bits used varies by how frequently an item appears in the set, but the characters used to encode are the same

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

What is an example of variable length, fixed encoding?

A

Morse Code

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

What is the most common form of variable length, variable encoding?

A

Huffman encoding

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

What are the key features of Huffman encoding?

A

No code is a prefix of another, it can used to compress any kind of file, the length and encoding depend on the file itself

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

What is required to decode something that has been Huffman encoded?

A

The Huffman tree that was used to encode it must be sent with the compressed file

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

What are the steps for Huffman encoding?

A
  1. Count the item frequency
  2. Sort items by frequency, least to most
  3. Build binary Huffman tree, starting with each item as a single node tree
  4. Combine the two trees with the smallest values, with the left child as the smaller, right as the larger, and parent as the sum of both
  5. Repeat until all only one tree remains
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you use a Huffman tree to encode something?

A

Assign each “edge” of the tree a value (usually 0 and 1) and trace down the branches to each item. The values passed, in order, is the encoded item

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

What are the two approaches for implementing Huffman’s algorithm, and which is better?

A

MinHeap or 2 Queues
Same time complexity for both, 2 Queues easier to implement

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

How do you find the average number of bits per item?

A

Sum of the bits*freq for each item, by the sum of all the frequencies

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

How do you find the Compression Ratio for a Huffman encoded file?

A

F-A/F * 100
F = Bits for fixed representation
A = Average number of bits

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

What is one benefit of Huffman encoding?

A

It guarantees the smallest binary encoding possible

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