If there are only two possible values in your data, compressing it is a lot easier and saves a lot of storage. For example, a stream of binary values, , can be compressed to an array of numbers, , and an array of characters, . The first character in the array of characters will show that the original data begins with , and the array of numbers will indicate the number of repetitions. Because there are only two potential values, if the first item of represents five repeats of , the second item, , will suggest seven repetitions of , and so on.
Now suppose Mike has tossed a coin times and has recorded in the case of heads and in the case of tails. You have the encoded data of all tosses in an array of numbers, , and an array of characters, . Can you write down the decoded data below?
Writing format: