What
Use dictionary to compress a ASCII encoded text.
Work best with repeated words.
How
Input: text: A sequence of characters in the ASCII character set.
Output: A sequence of indices into a dictionary.
- For each character c in the ASCII character set:
- A. Insert c into the dictionary at the index equal to c’s numeric code in ASCII.
- Set s to the first character from text.
- While text is not exhausted, do the following:
- A. Take the next character from text, and assign it to c.
- B. If s c is in the dictionary, then set s to s c.
- C. Otherwise (s c is not yet in the dictionary), do the following:
- i. Output the index of s in the dictionary.
- ii. Insert s c into the next available entry in the dictionary.
- iii. Set s to the single-character string c.
- Output the index of s in the dictionary.