1 / 28

Organizing Files for Performance

Data Compression. 6. Organizing Files for Performance. 6 .1. Data Compression. Introduction to Compression Methods in Data Compression Run-Length Coding Huffman Coding. Content. Data compression.

zyta
Télécharger la présentation

Organizing Files for Performance

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Compression 6 Organizing Files for Performance

  2. 6.1 Data Compression

  3. Introduction to Compression Methods in Data Compression Run-Length Coding Huffman Coding Content

  4. Data compression • Data compression methods are used to make files smaller by re/encoding data that goes into a file . • There are many reasons for making file smaller • Use less storage , resulting in cost saving • Can be transmitted faster , decreasing access time or, alternatively ,allowing the same access time with a lower And cheaper bandwidth • Can be processed faster sequentially

  5. Techniques of compressions • Using different notation • Suppressing Repeating Sequences • Assigning Variables Length Codes • Irreversible Compression Techniques (Lossy)

  6. Using different Notation • Fixed-Length fields are good candidates • Decrease the number of bits by finding a more compact notation • Cons. • unreadable by human • cost in encoding time • decoding modules  increase the complexity of s/w  used for particular application. • Example: The state fields in the person records. 6 bits (for 50 states) instead of 16. • It’s classified as redundancy reduction technique. • With so many costs, is this kind of compression worth it?

  7. Using different Notation • The notation used for representing information can often be made more compact. • EX if we are going to write a file that contains information about students such as name, marks , and major, we can declare the mark as byte instead of integer, in this way we can save a space. ST_REC = Name_Stu : string[50]; Mark_Stu : int ; byte Major_Stu : string[30]; string[3]; // using lookup table.

  8. Suppressing Repeating Sequences • Run-length encoding (RLE):encode sequencesof repeating values rather than writing all the values in the file. • EX: Suppose we wish to compress an image using run –length encoding, and we find that can be omit the byte 0xff from the representation of image . - How would we encode the following sequence of hexadecimal byte values ? 22 23 24 24 24 24 24 24 24 25 26 26 26 26 26 26 25 24 - The way: the first three pixels are to be copied in sequence. The runs of 24 and 26 are both run length encoded .the remaining pixels are copied in sequence ,the resulting sequence is: 22 23 ff 24 07 25 ff 26 06 25 24

  9. Suppressing Repeating Sequences • Run-length encoding (cont’d) • example of redundancy reduction • cons. • not guarantee any particular amount of space savings • under some circumstances, compressed image is larger than original image • Why? Can you prevent this?

  10. RLE Ex 1: Here we have a series of blue x 6, magenta x 7, red x 3, yellow x 3 and green x 4, that is: Ex 2:

  11. Assigning Variable-Length Codes • Morse code: oldest & most common scheme of variable-length code • Some values occur more frequently than others • that value should take the least amount of space • Huffman coding • base on probability of occurrence • determine probabilities of each value occurring • build binary tree with search path for each value • more frequently occurring values are given shorter search paths in tree

  12. Variable-length encoding • Any encoding scheme in which the codes are of different lengths. More frequently occurring codes are given shorter lengths than frequently occurring codes. Huffman encoding is an example of variable-length encoding. • Huffman code which determines the probabilities of each value occurring in the data set and then builds a binary tree in which the search path for each value represent the code for that value.

  13. Huffman Encoding • Compression • Typically, in files and messages, • Each character requires 1 byte or 8 bits • Already wasting 1 bit for most purposes! • Question • What’s the smallest number of bits that can be used to store an arbitrary piece of text? • Idea • Find the frequency of occurrence of each character • Encode Frequent characters short bit strings • Rarer characters longer bit strings

  14. Huffman Encoding • Encoding • Use a tree • Encode by followingtree to leaf • eg • E is 00 • S is 011 • Frequent characters E, T 2 bit encodings • Others A, S, N, O 3 bit encodings

  15. A 010 B : E 00 : N 110 : S 001 T 10 Huffman Encoding • Encoding • Use a tree • Inefficient in practice • Use a direct-addressed lookuptable • Finding the optimal encoding • Smallest number of bits torepresent arbitrary text

  16. Huffman Encoding • Divide and conquer • Decide on a root - n choices • Decide on roots for sub-trees - n choices • Repeat n times • O(n!) • Greedy Approach • Sort characters by frequency • Form two lowest weight nodes into a sub-tree • Sub-tree weight = sum of weights of nodes • Move new tree to correct place

  17. Huffman Encoding - Operation Initial sequence Sorted by frequency Combine lowest two into sub-tree Move it to correct place

  18. Huffman Encoding - Operation After shifting sub-tree to its correct place ... Combine next lowest pair Move sub-tree to correct place

  19. Huffman Encoding - Operation Move the new tree to the correct place ... Now the lowest two are the “14” sub-tree and D Combine and move to correct place

  20. Huffman Encoding - Operation Move the new tree to the correct place ... Now the lowest two are the the “25” and “30” trees Combine and move to correct place

  21. Huffman Encoding - Operation Combine last two trees

  22. Huffman Encoding - Decoding

  23. Huffman Encoding - Time Complexity • Sort keys O(n log n) • Repeat n times • Form new sub-tree O(1) • Move sub-tree O(logn)(binary search) • Total O(n log n) • Overall O(n log n)

  24. Irreversible Compression Techniques • Compression in which information is lost. • EX : Shrinking a raster image from 400 by 400 pixels to 100 by 100 pixels . • There is no way to determine what the original pixels were from the one new pixel. • Irreversible Compression is less common in data files than reversible compression but there are times when the info. That is lost of little or no value. • EX: Speech Compression.

  25. Lossy Compression Techniques • Some information can be sacrificed • Less common in data files • Shrinking raster image • 400-by-400 pixels to 100-by-100 pixels • 1 pixel for every 16 pixels • Speech compression • voice coding (the lost information is of no little or no value)

More Related