Run Length Encoding & Dictionary Coding

Cards (2)

  • What is Run-Length Encoding
    • Run-Length Encoding (RLE) is a form of data compression that condenses identical elements into a single value with a count. 
    • For a text file, "AAAABBBCCDAA" is compressed to "4A3B2C1D2A" 
    • The string has four 'A's, followed by three 'B's, two 'C's, one 'D', and two 'A's. RLE shows this as "4A3B2C1D2A" 
    • It is used in bitmap images to compress sequences of the same colour 
    • For example, a line in an image with 5 red pixels followed by 3 blue pixels could be represented as "5R3B" 
  • What is Dictionary Coding
    • Dictionary coding replaces recurring sequences with shorter, unique codes 
    • A 'dictionary' is compiled to map original sequences to special codes 
    • This method is effective for both text and binary data 
    • The phrase "for example" could be coded as 'FE' if 'FE' doesn't appear in the original text 
    • A sequence of binary numbers '1010' could be replaced by a shorter unique code