Presentation is loading. Please wait.

Presentation is loading. Please wait.

بسم الله الرحمن الرحيم My Project Huffman Code. Introduction Introduction Encoding And Decoding Encoding And Decoding Applications Applications Advantages.

Similar presentations


Presentation on theme: "بسم الله الرحمن الرحيم My Project Huffman Code. Introduction Introduction Encoding And Decoding Encoding And Decoding Applications Applications Advantages."— Presentation transcript:

1 بسم الله الرحمن الرحيم My Project Huffman Code

2 Introduction Introduction Encoding And Decoding Encoding And Decoding Applications Applications Advantages And Disadvantages Advantages And Disadvantages Length Of Code Length Of Code

3 Huffman Code Definition Huffman coding is coding technique used to compact data by representing the more common events with short codes and the less common events with longer codes using a binary tree. Huffman coding is coding technique used to compact data by representing the more common events with short codes and the less common events with longer codes using a binary tree.

4 Huffman Encoding The algorithm for Huffman encoding: Generate a leaf node for each input character. Generate a leaf node for each input character. Enter the character and its probability into the node. Enter the character and its probability into the node. Determine the two unvisited nodes with least probability and calculate their combined probability p. Determine the two unvisited nodes with least probability and calculate their combined probability p. Generate a node with probability p and insert the two chosen nodes as left (‘0’) and right(‘1’) son. Generate a node with probability p and insert the two chosen nodes as left (‘0’) and right(‘1’) son. Mark the left and right son as visited. Mark the left and right son as visited. Mark the new node as unvisited. Mark the new node as unvisited. If there is more than one unvisited node,continue with step3. If there is more than one unvisited node,continue with step3.

5 Huffman Encoding

6

7 The algorithm for decoding : Generate a tree equivalent to the encoding tree. Generate a tree equivalent to the encoding tree. Read input characterise and go left on a ‘0’ input go to right on a ‘1’ input, until a leaf is reached. Read input characterise and go left on a ‘0’ input go to right on a ‘1’ input, until a leaf is reached. Output the character encoded in the leaf and return to root. Output the character encoded in the leaf and return to root. Continue with step 2, until input is empty. Continue with step 2, until input is empty. Huffman Decoding

8

9 Huffman code Applications In Text Compression In Text Compression In Image Data In Image Data In MP3 Files In MP3 Files In Fax Machine In Fax Machine In Computer Security In Computer Security

10 Huffman Code Advantages The Huffman Code guarantees that no more than the ceil(log2(alphabetsize)) rightmost bits of the code can differ from zero. The Huffman Code guarantees that no more than the ceil(log2(alphabetsize)) rightmost bits of the code can differ from zero. The Huffman Code is efficient decoding The Huffman Code is efficient decoding The Huffman Code is NON-BLOCK. The Huffman Code is NON-BLOCK. The Huffman Code is NON-SINGULAR. The Huffman Code is NON-SINGULAR. The Huffman Code UNIQUELY DECODABLE. The Huffman Code UNIQUELY DECODABLE.

11 Huffman Code Advantages The Huffman Code INSTANTANEOUS The Huffman Code INSTANTANEOUS The Huffman Code is SYNCHRONIZATION The Huffman Code is SYNCHRONIZATION The Huffman Code is REDUNDANCY --. The Huffman Code is REDUNDANCY --. The Huffman Code is optimal when the probability of each input symbol is a power of two The Huffman Code is optimal when the probability of each input symbol is a power of two

12 Huffman Code Disadvantages - In the case of the encoding and the decoding, the Huffman code requires an effort for both the transmitter and the receiver. They both must know the table of codeword relating to the transmitted data. These are exactly the major disadvantages of the Huffman code. - Huffman codes exploit only nonuniformity in symbol distribution.

13 Length of a Huffman Code No Huffman code can be longer than alphabetsize-1. No Huffman code can be longer than alphabetsize-1. The maximum code length will be log2(1/number_of_symbols). The maximum code length will be log2(1/number_of_symbols).

14 Calculating Code lengths (N) of Huffman Code To calculate the code lengths of Huffman code we apply this method: Setup: make a heap containing the symbols, lowest probable symbol on top. Setup: make a heap containing the symbols, lowest probable symbol on top. Loop: take the 2 least probable nodes out of the heap, form a new node having the two nodes used to form it as children. Insert the new node back into the heap: Repeat until only one node is left (or alphabet-1 times; this is the same.) Loop: take the 2 least probable nodes out of the heap, form a new node having the two nodes used to form it as children. Insert the new node back into the heap: Repeat until only one node is left (or alphabet-1 times; this is the same.) that node is the root. that node is the root.

15 Coding Theory Project Name : Nayef Abdullah ID : 9911-2965 Instructor : Dr.Maryam Alkandari


Download ppt "بسم الله الرحمن الرحيم My Project Huffman Code. Introduction Introduction Encoding And Decoding Encoding And Decoding Applications Applications Advantages."

Similar presentations


Ads by Google