Chapter 9 · SimulationString Compression Algorithms? ← Chapter 9 Input RLE LZW Prepare Next Step Auto Play ResetPress Prepare to begin.Compressed OutputRatio: —No result yet.RunsRuns appear here.CloseString Compression AlgorithmsRun-length encoding (RLE) and Lempel-Ziv-Welch (LZW) are shown step by step.How to useType an input text (up to 24 characters) and choose an algorithm. Changing the algorithm loads a suitable example.Prepare generates all the steps; Next Step advances one step, Auto Play plays the remaining steps, and Reset clears the run.Yellow cell: the character being processed. Green cells: the current run (RLE).The lines at the bottom keep the last few steps; the ratio appears when the run finishes.Run-length encoding (RLE)RLE replaces each run of identical symbols with a count-symbol pair, for example AAAAABB → 5A2B. It works well when the input has long runs; otherwise it can make the output longer.Lempel-Ziv-Welch (LZW)LZW starts with a dictionary of the single characters in the input. While scanning, it extends the current string w with the next character c. If wc is in the dictionary, w = wc; otherwise it writes the code of w to the output, adds wc as a new code, and restarts with w = c. The dictionary grows as new strings appear.In the dictionary panel, the green entry is the current w and the yellow entry is the code added in this step.Compression ratioRatio = compressed units / original units. For RLE the units are the characters of the output pieces; for LZW they are the codes written.ComplexityAlgorithmTimeExtra memoryRLEO(n)O(1) besides the outputLZWExpected O(n) (hash dictionary)O(n) dictionary