Initialize Table With Single Character Strings P First Input Character

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

LAMPEL ZIV ALGORITHM:

This algorithm was developed by Abraham lampel and Jacob Zev in 19777.Lampel Ziv algorithm is a
decompression algorithm that is type of loseless algorithm. The data is fully conserved in the
implementation of the data. It not only maintains data but also reduces memory occupation of data.
It reduces redundancy in data hence less memory is required to keep data. It has vast application. In
the initial formation of algorithm, no implementation was explained so it has different variants in
market like LZ77 and LZ78.

Explanation:

The basis of its working is similar to Run-Length algorithm i-e: Repetition of worlds or set of words.
The algorithm actually takes up the input and then breaks it on the basis of repetition of data. Then
it encodes each phrase. The encoded data has following things:

 Code of phrase
 Location of prefix
 Value of last bit

The parsed string is stored in the form of table that has phrases and their codes in it. In this way,
there is no iteration of data and input is converted in form of dictionary of most used words.

Functionality:

Ziv-Lempel algorithm works in following way:

 The set of most used words is stored in form of tables.


 It used table of codes usually 4096. Each character is assigned 1 byte.
 The table is filled in two steps
o Index 0-255 with input file
o 256-2096 with the compressed strings
 During encoding, LZ continues to add repeated strings in table
 The input string is parsed in smallest, unique set of string and stored in table
 Once input string is divided in substrings, they are assigned numeric values then. It is done in
following way
o If the substring is new, it is assigned zero
o If it has occurred before, the code of already existing string is attached to it.
 Then these vales are converted to ASCII codes
 The converted codes of all substrings are joined to give the code of entire input string.
 This encoded string takes less time to process and less memory.

Pseudo Code:

Initialize table with single


character strings P = first input
character
WHILE not end of
input stream
C = next input
character

IF P + C is in the
string table
P=P+C

ELSE
output the code for P
add P + C to the
string
table P =
C

END WHILE

output code for P 5

Graphical Representation:
Let us consider an example:

wabbawabba
We will make dictionary of all possible unique sub strings.
f k c c k f k c c k

Index : 1

Substring : f

f k c c k f k c c k

Index : 2
Substring : k

f k c c k f k c c k

Index : 3

Substring : c

f k c c k f k c c k

Index : 4

Substring : fk

f k c c k f k c c k

Index : 5

Substring : kc

f k c c k f k c c k

Index : 6

Substring : cc

f k c c k f k c c k

Index : 7

Substring : ck

f k c c k f k c c k

Index : 8

Substring : kf
f k c c k f k c c k

Index : 9

Substring : fkc

f k c c k f k c c k

Index : 10

Substring : cck

Final Code:

The final code of string is 31221461.

Applications of Lempel-Ziv Algorithm:

 It is widely used in UNIX utility


 It has applications in GIF
 Many files are compressed using LZ techniques

Advantages of Lempel Ziv Algorithm:

 It doesn’t require any basic knowledge from source


 It is simple and fast to execute
 It has very low cost and takes less memory in system.
 It is asymptotically optimal; redundancy becomes zero when length goes infinity.
 It is widely used due to its efficiency.

You might also like