Click here to Skip to main content
15,885,855 members
Articles / Programming Languages / C#

Project Tool

Rate me:
Please Sign up or sign in to vote.
4.69/5 (10 votes)
23 Sep 2007CPOL3 min read 54.5K   1.7K   73  
Backup your C# solution and projects for archive or source code sharing. Temporary or unused files are excluded.
This improved version of the original LZ78 algorithm is perhaps the most
famous modification. Published by Terry Welch in 1984, it basically
applies the LZSS principle of not explicitly transmitting the next nonmatching
symbol to the LZ78 algorithm. 

The only remaining output of this improved algorithm are fixed-length references 
to the dictionary (indexes).  The dictionary has to be initialized with
all the symbols of the input alphabet and this initial dictionary needs to
be made known to the decoder.

Encode Algorithm:

initialize dictionary;
word <- NIL;

while (there is input)
{
	symbol <- next symbol from input;
	phrase <- word + symbol;
	
	if (phrase exists in the dictionary)
	{
		word <- phrase;
	}
	else
	{
		output (index(word));
		add phrase to the dictionary;
		word <- symbol;
	}
}
output (index(word));

Decode Algorithm:

initialize dictionary;
phrase <- NIL;

while (there is input)
{
	wordIndex <- next code from input;
	
	if (wordIndex exists in the dictionary)
	{
		word <- dictionary[wordIndex];
		phrase <- phrase + head(word);
		if(phrase.Length > 1)
		{
			add phrase to the dictionary;
		}
	}
	else
	{
		phrase <- phrase + head(phrase);
		add phrase to the dictionary;
		word <- phrase; //word <- dictionary[wordIndex];
	}
	phrase <- word;
	output (word);
}

In the original proposal, the pointer size is chosen to be 12 bit, allowing
for up to 4096 dictionary entries. Once this limit has been reached, the
dictionary becomes static.

GIF image compression is originally developed by CompuServe in the late 1980s,
the GIF file format employs the LZW technique for compression.

LZC is the variant of the LZW. It compresses according to the LZW principle
but returns to variable-length pointers like the original LZ78 algorithm.
It first starts with 9-bit indexes for the first 512 dictionary entries, 
then continues with 10-bit codes and so on until the user-specified limit has been
reached. Finally, the algorithm becomes a static encoder, regularly checking
the compression ratio. When it detects a decrease, it throws away the
dictionary and starts building up a new one from scratch.

LZFG uses the dictionary building technique from the original LZ78 algorithm,
but stores the elements in a trie data structure. In addition, a
sliding window like LZ77��s is used to remove the oldest entries from the
dictionary.

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect YunCheDa Hangzhou
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions