lec22 - D s n translation of n (lookup n in D ) else s n s...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Encoding Algorithm Algorithm LZW-Encode( input ) Initialize a dictionary D with 128 ASCII chars String s the first character in input While input has more characters do char c next character in input if s + c is in D s s + c else Output code for s Add s + c to D , using the first available number as code s c // end of the loop Output code for s Lecture 22, Lempel-Ziv-Welch Compression p. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Encoding Example Example: COCOA AND BANANAS s ... A B C D ... N O ... S ... ... code ... 65 66 67 68 ... 78 79 ... 83 ... 95 ... step s c output s + c code 1 C O 67 CO 128 2 O C 79 OC 129 3 C O 4 CO A 128 COA 130 5 A 65 A 131 6 A 95 A 132 7 A N 65 AN 133 8 N D 78 ND 134 9 D 68 D 135 10 B 95 B 136 11 B A 66 BA 137 12 A N 13 AN A 133 ANA 138 14 A N 15 AN A 16 ANA S 138 ANAS 139 17 S 83 Lecture 22, Lempel-Ziv-Welch Compression p. 2
Background image of page 2
Decoding Algorithm Algorithm LZW-Decode( input ) Initialize a dictionary D with 128 ASCII chars int n first input code String s n translation of n (lookup n in D ) Output s n While the input has more code String s o s n n next input code if n is in
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: D s n translation of n (lookup n in D ) else s n s o + 1st char of S o Output s n char c 1st character of s n Add s o + c to dictionary with the rst available code Lecture 22, Lempel-Ziv-Welch Compression p. 3 Decoding Example Example: 67 79 128 65 95 65 78 68 95 66 133 138 83 s ... A B C D ... N O ... S ... ... code ... 65 66 67 68 ... 78 79 ... 83 ... 95 ... step n s n c s o + c code output 67 C C 1 79 O O CO 128 O 2 128 CO C OC 129 CO 3 65 A A COA 130 A 4 95 A 131 5 65 A A A 132 A 6 78 N N AN 133 N 7 68 D D ND 134 D 8 95 D 135 9 66 B B B 136 B 10 133 AN A BA 137 AN 11 138 ANA A ANA 138 ANA 12 83 S S ANAS 139 S Lecture 22, Lempel-Ziv-Welch Compression p. 4...
View Full Document

Page1 / 4

lec22 - D s n translation of n (lookup n in D ) else s n s...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online