80 likes | 223 Views
Lossless Compression Page 294-298. Lauren D’Arcangelo. Overview . Dictionary encoding: create a dictionary (a table) of strings used during the communication session. Steps to compression Steps to decompression. Compression…. Decompressed String: BAABABBBAABBBBAA
E N D
Lossless CompressionPage 294-298 Lauren D’Arcangelo
Overview • Dictionary encoding: create a dictionary (a table) of strings used during the communication session. • Steps to compression • Steps to decompression
Compression… • Decompressed String:BAABABBBAABBBBAA • Step 1:Extract smallest substring from original string (B). • B is index 1. • B is inserted in the compressed string. • Remaining String: AABABBBAABBBBAA • Step 2:Extract next smallest substring from the remaining string (A). • A is index 2. • A is inserted in the compressed string. • Remaining String: ABABBBAABBBBAA
Compression… • Remaining String: ABABBBAABBBBAA • Step 3: Extract the next smallest substring from the original string, that isn’t in the dictionary (AB). • AB is index 3 • Find the substring without the last character (A). • The index for A is 2, replace A with 2 and insert 2B in the compressed string.
Compression… • Remaining String:ABBBAABBBBAA • Step 4:Extract ABB, because A and AB are already in the dictionary. • ABB is index 4. • Find the index of the substring without the last character (AB) which is 3. • 3B is inserted into the compressed string. • When the steps are completed the final compressed string is: B, A, 2B, 3B, 1A, 4B, 5A
Decompression • Compressed String:B, A, 2B, 3B, 1A, 4B, 5A • Step 1: Find first substring of the compressed string (B). B has no index; B is inserted to decomposed string. • Step 2: Find the second substring (A). Insert A into the decompressed string. • Step 3: Find the third substring (2B). Search the dictionary and replace the index 2 with the substring A. AB is added to the decomposed string. • Step 4: Find the fourth substring (3B). Search the dictionary and replace the index 3 with the substring AB. The substring ABB is added to decompressed string. • The final decompressed string is: BAABABBBAABBBBAA