Dt Compression Lossless And Lossy Compression Reduce the size of dt. ƒ Reduces storge spce nd hence storge cost. Compression rtio = originl dt size/compressed dt size ƒ Reduces time to retrieve nd trnsmit dt. compresseddt = compress(originldt) decompresseddt = decompress(compresseddt) When originldt = decompresseddt, the compression is lossless. When originldt!= decompresseddt, the compression is lossy. Lossless And Lossy Compression Lossy compressors generlly otin much higher compression rtios thn do lossless compressors. ƒ Sy vs.. Lossless compression is essentil in pplictions such s text file compression. Lossy compression is cceptle in mny imging pplictions. ƒ In video trnsmission, slight loss in the trnsmitted video is not noticed y the humn eye. Text Compression Lossless compression is essentil. Populr text compressors such s zip nd Unix s compress re sed on the LZW (Lempel-Ziv-Welch) method.
Chrcter sequences in the originl text re replced y s tht re dynmiclly determined. The tle is not end into the compressed text, ecuse it my e reconstructed from the compressed text during decompression. Assume the letters in the text re limited to {, }. ƒ In prctice, the lphet my e the chrcter ASCII set. The chrcters in the lphet re ssigned numers eginning t. The initil tle is: Originl text = Compression is done y scnning the originl text from left to right. Find longest prefix p for which there is in the tle. Represent p y its pcode nd ssign the next ville numer to pc, where c is the next chrcter in the text tht is to e compressed. Originl text = p = pcode = c = Represent y nd enter into the tle. Compressed text =
Originl text = Compressed text = p = pcode = c = Represent y nd enter into the tle. Compressed text = Originl text = Compressed text = p = pcode = c = Represent y nd enter into the tle. Compressed text = Originl text = Compressed text = p = pcode = c = Represent y nd enter into the tle. Compressed text = Originl text = Compressed text = p = pcode = c = Represent y nd enter into the tle. Compressed text =
7 Originl text = Compressed text = p = pcode = c = Represent y nd enter into the tle. Compressed text = 7 8 Originl text = Compressed text = p = pcode = c = Represent y nd enter into the tle. Compressed text = Originl text = Compressed text = p = pcode = 8 c = Represent y 8 nd enter into the tle. Compressed text = 8 Originl text = Compressed text = 8 p = pcode = 8 c = null Represent y 8. Compressed text = 88
Dictionry. Code Tle Representtion ƒ Pirs re (, element) = (,). ƒ Opertions re : get() nd put(, ) Limit numer of s to. Use hsh tle. ƒ Convert vrile length s into fixed length s. ƒ Ech hs the form pc, where the string p is tht is lredy in the tle. ƒ Replce pc with (pcode)c. Code Tle Representtion 7 8 9 8 Originl text = Compressed text = 88 Convert s to text from left to right. represents. Decompressed text = pcode = nd p =. p = followed y next text chrcter (c) is entered into the tle. Originl text = Compressed text = 88 represents. Decompressed text = pcode = nd p =. lstp = followed y first chrcter of p is entered into the tle.
Originl text = Compressed text = 88 represents. Decompressed text = pcode = nd p =. lstp = followed y first chrcter of p is entered into the tle. Originl text = Compressed text = 88 represents Decompressed text =. pcode = nd p =. lstp = followed y first chrcter of p is entered into the tle. Originl text = Compressed text = 88 represents Decompressed text =. pcode = nd p =. lstp = followed y first chrcter of p is entered into the tle. Originl text = Compressed text = 88 represents Decompressed text =. pcode = nd p =. lstp = followed y first chrcter of p is entered into the tle.
7 Originl text = Compressed text = 88 represents Decompressed text =. pcode = nd p =. lstp = followed y first chrcter of p is entered into the tle. 7 8 Originl text = Compressed text = 88 8 represents??? When is not in the tle, its is lstp followed y first chrcter of lstp. lstp = So 8 represents. Originl text = Compressed text = 88 8 represents Decompressed text =. pcode = 8 nd p =. lstp = followed y first chrcter of p is entered into the tle. Dictionry. Code Tle Representtion ƒ Pirs re (, element) = (, wht the represents) = (, Key). ƒ Opertions re : get() nd put(, ) Keys re integers,,, Use D rry Tle. ƒ Tle[] = Key. ƒ Ech hs the form pc, where the string p is tht is lredy in the tle. ƒ Replce pc with (pcode)c.
Time Complexity Compression. ƒ O(n) expected time, where n is the length of the text tht is eing compressed. Decompression. ƒ O(n) time, where n is the length of the decompressed text.