• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

LZW encoding algorithm

26 Jan 2018

Reading time ~2 minutes

LZW encoding algorithm

LZW encoding algorithm

1. at the start, the dictionary contains all possible individual charactrs. and P is empty
2. C = next character in the charstream
3. si the string P+C present in the dictionary?
  a) if it is, 
      P = P + C (extend P with C);

  b)if not,
      i. output the code word which denotes P to the codestream;
      ii. add the string P+C to the dictionary
      iii. P=C(P now contanis only the character C)


1. At the start the dictionary contains all possible charstream.
2. cW = the first code word.
3. output the string.cW to the charstream.
4. pW = cW
5. cW = next code word.
6. is the String.cW present in the dictionary?
    if it is, 
        a) ouput the string.cW to the charstream;
        b) P := string.pW;
        c) C := the first character of the string.cW
        d) add the string P+C to the dictionary;

    if not, 
        a) P = string.pW;
        b) C = the first character of the string.pW;
        c) ouput the string P+C to the charstream and add it to the dictionary (now it corresponds to the cW)
7. Are there more code words in the codestream?
    a) if yes, go back to step  4;
    b) if not, End

LZW 인코딩 알고리즘

1. 처음에는 사전에 가능한 모든 개인 문자가 들어 있습니다. P는 비어 있습니다.
2. C = charstream의 다음 문자
3. 사전에 P + C 문자열이 있습니까?
  a) 그렇다면,
      P = P + C (C와 P 연장);

  b) 그렇지 않다면,
      i. P를 코드 워드에 출력하고;
      ii. 사전에 문자열 P + C를 추가합니다.
      iii. P = C (이제 P는 문자 C 만 사용)


1. 처음에는 사전에 가능한 모든 charstream이 들어 있습니다.
2. cW = 첫 번째 코드 워드.
3. string.cW를 charstream으로 출력하십시오.
4. pW = cW
5. cW = 다음 코드 워드.
6. 사전에 String.cW가 있습니까?
    그렇다면,
        a) string.cW를 charstream에 출력한다.
        b) P : = string.pW;
        c) C : = string.cW의 첫 번째 문자
        d) P + C 문자열을 사전에 추가합니다.

    그렇지 않다면,
        a) P = 문자열 .pW;
        b) C = 문자열의 첫 번째 문자 .pW;
        c) 문자열 P + C를 charstream에 놓고 사전에 추가합니다 (이제는 cW에 해당함)
7. 코드 스트림에 더 많은 코드 단어가 있습니까?
    a) 그렇다면 4 단계로 되돌아갑니다.
    b) 그렇지 않다면, 끝


lzw Share Tweet +1