Efficient Data Compression Scheme using Dynamic Huffman Code Applied on Arabic Language

: The development of an efficient compression scheme to process the Arabic language represents a difficult task. This paper employs the dynamic Huffman coding on data compression with variable length bit coding, on the Arabic language. Experimental tests have been performed on both Arabic and English text. A comparison was made to measure the efficiency of compressing data results on both Arabic and English text. Also a comparison was made between the compression rate and the size of the file to be compressed. It has been found that as the file size increases, the compression ratio decreases for both Arabic and English text. The experimental results show that the average message length and the efficiency of compression on Arabic text was better than the compression on English text. Also, results show that the main factor which significantly affects compression ratio and average message length was the frequency of the symbols on the text.


INTRODUCTION
Among numerous types of information produced broadcasted or recorded by electronic information processing systems and tools, the degree of duplication in data is adequately high to allow the output flow to contain considerably fewer bits than the input flow.In conditions, the output flow may contain more bits than the input flow.The real ratio of the numbers of bits is dependent on the uniqueness of the actual input data flow.Compression by this algorithm is lossless, i.e. it is probable to restore exactly the original version of data by earnings of a corresponding decompression algorithm.The algorithm contains features which assist its implementation in data storage and retrieval tools which handles, in a sequential way, data records of varying extent.Compression is used just about everywhere.All the images you get on the web are compressed, typically in the JPEG or GIF formats, most modems use compression, HDTV will be compressed using MPEG-2 and several file systems automatically compress files when stored [1] .
The oldest and most widely used codes, ASCII and EBCDIC, are examples of block-block codes, mapping an alphabet of 64 (or 256) single characters onto 6-bit (or 8-bit) codewords.The codes featured in this survey are of the block-variable, variable-variable and variable-block types.For example, in text file processing each character may constitute a message, or messages may be defined to consist of alphanumeric and non-alphanumeric strings [2] .The compression algorithms allow for records of different size and compressibility, along with File Marks, to be efficiently encoded into an output stream in which little or no additional control information is needed to later decode user data [3] .
In addition to the categorization of data compression schemes with respect to message and codeword lengths, these methods are classified as either static or dynamic.A static method is one in which the mapping from the set of messages to the set of codewords is fixed before transmission begins, so that a given message is represented by the same codeword every time it appears in the message ensemble.The classic static defined-word scheme is Huffman coding.In Huffman coding, the assignment of codewords to source messages is based on the probabilities with which the source messages appear in the message ensemble.Messages which appear more frequently are represented by short codewords; messages with smaller probabilities map to longer codewords.These probabilities are determined before transmission begins.A code is dynamic if the mapping from the set of messages to the set of codewords changes over time.For example, dynamic Huffman coding involves computing an approximation to the probabilities of occurrence "on the fly", as the ensemble is being transmitted.The assignment of codewords to messages is based on the values of the relative frequencies of occurrence at each point in time.A message x may be represented by a short codeword early in the transmission because it occurs frequently at the beginning of the ensemble, even though its probability of occurrence over the total ensemble is low.Later, when the more probable messages begin to occur with higher frequency, the short codeword will be mapped to one of the higher probability messages and x will be mapped to a longer codeword [2] .There are two methods to represent data before transmission: Fixed length code: In this method it allows computers to efficiently process data which means that all characters are of equal length, even though they are not transmitted with equal frequency E.g. vowels, blanks used more often consonants, etc. ASCII is an example of a fixed length code.There are 100 printable characters in the ASCII character set and a few non printable characters, giving 128 total characters.Since log 128 = 7, ASCII requires 7 bits to represent each character.The ASCII character set treats each character in the alphabet equally and makes no assumptions about the frequency with which each character occurs [4] .

Variable length code:
In this method most frequently transmitted characters are compressed; represented by fewer bits than least frequently transmitted and compressing data saves on data communications costs.A variable length code is based on the idea that for a given alphabet, some letters occur more frequently than others.This is the basis for much of information theory and this fact is exploited in compression algorithms.To use as few bits as possible to encode data without "losing" information.More sophisticated compression techniques can use compression techniques that actually discard information [4] .
There are two dimensions along which each of the schemes discussed here may be measured, algorithm complexity and amount of compression.When data compression is used in a data transmission application, the goal is speed.Speed of transmission depends upon the number of bits sent, the time required for the encoder to generate the coded message and the time required for the decoder to recover the original ensemble.In a data storage application, although the degree of compression is the primary concern [2] .Many lossless data compression algorithms exist.Some of the main techniques in use are the Huffman [5] .
When compressed data is retrieved from storage or received over a communications link, it is expanded back to its original form, based on the code.
A Huffman Code is an optimal prefix code that guarantees unique decodability of a file compressed using the code.The code was devised by Huffman as part of a course assignment at MIT in the early 1950s.Huffman code constructed by using a code tree, but starting at the leaves and it provide compact code by using the binary Huffman code construction method and it has uniquely decodable code or a prefix-free code which requires that no codeword is a proper prefix of any other codeword [4] .
The Huffman coding algorithm produces an optimal variable length prefix code for a given alphabet in which frequencies are preassigned to each letter in the alphabet.Symbols that occur more frequently have shorter Code words than symbols that occur less frequently.The two symbols that occur least frequently will have the same codeword length [6] .Entropy is a measure of the information content of data.The entropy of the data will specify the amount of lossless data compression can be achieved.However, finding the entropy of data sets is non trivial [7] .We have to notice that there is no unique Huffman code because Assigning 0 and 1 to the branches is arbitrary and if there are more nodes with the same probability, it doesn't matter how they are connected.
The average message length as a measure of efficiency of the code has been adopted in this work.Avg L = L1 * P (1) + L2 * P (2) + ….. + Li * P (i) Avg L = Li * P (i) Also the compression ratio as a measure of efficiency has been used.Comp.Ratio = Compressed file size / source file size * 100 % The task of compression consists of two components, an encoding algorithm that takes a message and generates a "compressed" representation (hopefully with fewer bits) and a decoding algorithm that reconstructs the original message or some approximation of it from the compressed representation [1] .

Demonstration examples Example 1:
This example is derived from reference [4] Suppose that we have a file of 100K characters.To keep the example simple, suppose that each character is one of the 8 letters from a through h.Since we have just 8 characters, we need just 3 bits to represent a character, so the file requires 300K bits to store.Suppose that we have more information about the file: the frequency which each character appears.The idea is that we will use a variable length code instead of a fixed length code (3 bits for each character), with fewer bits to store the common characters and more bits to store the rare characters.At one obvious extreme, if only 2 characters actually appeared in the file, we could represent each one with just one bit and reduce the storage from 300K bits to 100K bits (plus a short header explaining the encoding).It turns out that all characters can appear, but that as long as each one does not appear nearly equally often (100K/8 times in our case), then we can probably save space by encoding.
For example, suppose that the characters appear with the following frequencies and following codes as shown in Table 1.Then the variable-length coded version will take not 300K bits but 45K. 1 + 13K. 3 + 12K. 3 + 16K. 3 + 9K. 4 + 5K. 4 = 224K bits to store, a 25% saving.In fact this is the optimal way to encode the 6 characters present.
We consider only codes in which no code is a prefix of any other code; such codes are called prefix codes (though perhaps they should be called prefix-free codes).The attraction of such codes is that it is easy to encode and decode data.To encode, we need only concatenate the codes of consecutive characters in the message.So for example "face" is encoded as "110001001101".To decode, we have to decide where each code begins and Ends, since they are no longer all the same length.But this is easy, since, no codes share a prefix.This means we need only scan the input string from left to right and as soon as we recognize a code, we can print the corresponding character and start looking for the next code.In the above case, the only code that begins with "1100..." or a prefix is "f", so we can print "f" and start decoding "0100..." get "a", etc.
To see why the no-common prefix property is essential, suppose that we tried to encode "e" with the shorter code "110" and tried to decode "1100"; we could not tell whether this represented "ea" or "f".(Furthermore, one can show that one cannot compress any better with a non-prefix code, although we will not show this here.) We can represent the decoding algorithm by a binary tree, where each edge represents either 0 or 1 and each leaf corresponds to the sequence of 0s and 1s traversed to reach it, i.e. a particular code.Since no prefix is shared, all legal codes are at the leaves and decoding a string means following edges, according to the sequence of 0s and 1s in the string, until a leaf is reached.Fig. 1 shows the tree for the above code.

Fixed Length Code
Variable Length Code Fig. 1: Fixed length vs. variable length representation Each leaf is labeled by the character it represents (before the colon), as well as the frequency with which it appears in the text (after the colon, in 1000s).Each internal node is labeled by the frequency with which all leaf nodes under it appear in the text (i.e. the sum of their frequencies).The bit string representing each character is also shown beneath each leaf.
Example 2: Suppose we want to decode the message " " using Huffman code.Table 2 shows the Huffman data compression and Fig. 2 shows the Huffman representation tree.

RESULTS
A series of experimental tests have been performed to measure the efficiency of compressing data results on both Arabic and English text.We compare both Arabic and English texts of different sizes using Huffman compression algorithm.It has been shown that as the file size increases, the compression ratio on Arabic Text decreases as well as the average message length.This is expected because when the file size increases the frequency of the symbols will increase, so we have better compression on larger files.-----------------------------------------------------------------------  ------------------------------  and English Text we found that the time required to compress files increases as file size increases.However, the rate of change of the time required to compress files with larger sizes is small (Table 3 and Table 4).Additionally it has been found that the efficiency of compression on Arabic language is better than on English language (Fig. 5).

CONCLUSION
It has been found that the compression on both Arabic and English text saves space and reduces transmission time.Also we found that as the file size increases the compression ratio decreases for both Arabic and English text as will as the average message length and that is expected because when the file size increases the frequency of the symbols will increase, so we expect to have better compression on large files.We also found that the efficiency of compression on Arabic text is better than compression on English text.Additionally, results show that the main factor which significantly affects compression ratio and average message length is the frequency of the symbols on the text.

Fig. 5 :
Fig. 5: Comparison between compression on Arabic and English Text

Table 2 :
Huffman data compression

Table 3 :
The effect of file size on compression for Arabic text File Size Statistics -

Table 4 :
The effect of file size on compression for English text File Size Statistics -

Table 3 and
Fig.3show the effect of file size on compression for different Arabic text.Also same resulted for English text, when the file size increases the compression rate and the average message length decreases.Clearly Table4and Fig.4show the effect of file size on compression for different English text.Also