This question evaluates understanding of simple lossless compression techniques and related competencies such as string processing and parsing for run-length encoding, bit-level operations and packing for fixed-width integer compression, and algorithmic complexity analysis.
You are asked to implement two related compression/decompression schemes: Run-Length Encoding (RLE) and bit-packing.
Implement RLE compression and decompression for a string consisting of characters in the ASCII range.
"AAABCCDDDD"
.
"3A1B2C4D"
.
Requirements:
"1B"
).
"3A1B2C4D"
) and reconstructs the original string (e.g.,
"AAABCCDDDD"
).
Describe the time and space complexity of your compression and decompression algorithms.
You are given an array of non-negative integers, each guaranteed to be in the range [0, 15] (i.e., each value fits in 4 bits).
[3, 15, 0, 7]
.
[3, 15]
:
3
in binary (4 bits) is
0011
.
15
in binary (4 bits) is
1111
.
00111111
(0x3F).
Implement a function/method that:
[0..15]
as input.
n
, and reconstructs the original array of integers.
n
is provided and matches the original length.
Again, describe the time and space complexity of your compression and decompression algorithms.
You do not need to provide code in a specific language for this prompt, but your explanation should be detailed enough that code could be written directly from it.