© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. CPUs zExample: data compressor.

Slides:



Advertisements
Similar presentations
CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
Advertisements

Formal Language, chapter 4, slide 1Copyright © 2007 by Adam Webber Chapter Four: DFA Applications.
Lecture 4 (week 2) Source Coding and Compression
© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Program design and analysis zCompilation flow. zBasic statement translation. zBasic optimizations.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
Greedy Algorithms (Huffman Coding)
Data Compressor---Huffman Encoding and Decoding. Huffman Encoding Compression Typically, in files and messages, Each character requires 1 byte or 8 bits.
Huffman Coding: An Application of Binary Trees and Priority Queues
Chapter 3 CPUs 金仲達教授 清華大學資訊工程學系 (Slides are taken from the textbook slides)
A Data Compression Algorithm: Huffman Compression
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Data Compression Basics & Huffman Coding
1 Lossless Compression Multimedia Systems (Module 2) r Lesson 1: m Minimum Redundancy Coding based on Information Theory: Shannon-Fano Coding Huffman Coding.
Lossless Compression Multimedia Systems (Module 2 Lesson 3)
Data Structures and Algorithms Huffman compression: An Application of Binary Trees and Priority Queues.
1 Project 7: Huffman Code. 2 Extend the most recent version of the Huffman Code program to include decode information in the binary output file and use.
CS 46B: Introduction to Data Structures July 30 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Noiseless Coding. Introduction Noiseless Coding Compression without distortion Basic Concept Symbols with lower probabilities are represented by the binary.
Algorithm Design & Analysis – CS632 Group Project Group Members Bijay Nepal James Hansen-Quartey Winter
CIS Computer Programming Logic
Faculty of Engineering and Applied Science University of Ontario Institute of Technology Canada Faculty of Engineering and Applied Science University of.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Data Compression1 File Compression Huffman Tries ABRACADABRA
1 Analysis of Algorithms Chapter - 08 Data Compression.
Stack. Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data.
1 Huffman Codes Drozdek Chapter Objectives You will be able to Construct an optimal variable bit length code for an alphabet with known probability.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
Compression.  Compression ratio: how much is the size reduced?  Symmetric/asymmetric: time difference to compress, decompress?  Lossless; lossy: any.
The LZ family LZ77 LZ78 LZR LZSS LZB LZH – used by zip and unzip
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Huffman coding Content 1 Encoding and decoding messages Fixed-length coding Variable-length coding 2 Huffman coding.
© 2004 Goodrich, Tamassia Hash Tables1  
Priority Queues, Trees, and Huffman Encoding CS 244 This presentation requires Audio Enabled Brent M. Dingle, Ph.D. Game Design and Development Program.
1 Chapter 7 Skip Lists and Hashing Part 2: Hashing.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Main Index Contents 11 Main Index Contents Complete Binary Tree Example Complete Binary Tree Example Maximum and Minimum Heaps Example Maximum and Minimum.
1 Huffman Codes. 2 ASCII use same size encoding for all characters. Variable length codes can produce shorter messages than fixed length codes Huffman.
Lecture 12 Huffman Algorithm. In computer science and information theory, a Huffman code is a particular type of optimal prefix code that is commonly.
بسم الله الرحمن الرحيم My Project Huffman Code. Introduction Introduction Encoding And Decoding Encoding And Decoding Applications Applications Advantages.
Compression techniques Adaptive and non-adaptive.
© 2000 Morgan Kaufman Overheads for Computers as Components CPUs zExample: data compressor.
Prof. Paolo Ferragina, Algoritmi per "Information Retrieval" Basics
Huffman code and Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
Stack. ADS2 Lecture 1010 The Stack ADT (GoTa §5.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Chapter 1.2 Introduction to C++ Programming
3.3 Fundamentals of data representation
Chapter 1.2 Introduction to C++ Programming
HUFFMAN CODES.
B/B+ Trees 4.7.
Assignment 6: Huffman Code Generation
Chapter 1.2 Introduction to C++ Programming
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Chapter 1.2 Introduction to C++ Programming
Applied Algorithmics - week7
C Basics.
Overheads for Computers as Components
Introduction to the C Language
CIS16 Application Development and Programming using Visual Basic.net
Chapter Four: DFA Applications
Overheads for Computers as Components 2nd ed.
Processes and operating systems
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Introduction to Programming
Podcast Ch23d Title: Huffman Compression
Presentation transcript:

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. CPUs zExample: data compressor.

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Goals zCompress data transmitted over serial line. yReceives byte-size input symbols. yProduces output symbols packed into bytes. zWill build software module only here.

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Collaboration diagram for compressor :input:data compressor:output 1..n: input symbols 1..m: packed output symbols

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Huffman coding zEarly statistical text compression algorithm. zSelect non-uniform size codes. yUse shorter codes for more common symbols. yUse longer codes for less common symbols. zTo allow decoding, codes must have unique prefixes. yNo code can be a prefix of a longer valid code.

v Overheads for Computers as Components 2 nd ed. Huffman example characterP a.45 b.24 c.11 d.08 e.07 f.05 P=1 P=.55 P=.31 P=.19 P=.12

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Example Huffman code zRead code from root to leaves: a1a1 b01 c0000 d0001 e0010 f0011

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Huffman coder requirements table

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Building a specification zCollaboration diagram shows only steady- state input/output. zA real system must: yAccept an encoding table. yAllow a system reset that flushes the compression buffer.

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. data-compressor class data-compressor buffer: data-buffer table: symbol-table current-bit: integer encode(): boolean, data-buffer flush() new-symbol-table()

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. data-compressor behaviors zencode: Takes one-byte input, generates packed encoded symbols and a Boolean indicating whether the buffer is full. znew-symbol-table: installs new symbol table in object, throws away old table. zflush: returns current state of buffer, including number of valid bits in buffer.

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Auxiliary classes data-buffer databuf[databuflen] : character len : integer insert() length() : integer symbol-table symbols[nsymbols] : data-buffer len : integer value() : symbol load()

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Auxiliary class roles zdata-buffer holds both packed and unpacked symbols. yLongest Huffman code for 8-bit inputs is 256 bits. zsymbol-table indexes encoded verison of each symbol. yload() puts data in a new symbol table.

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Class relationships symbol-table data-compressor data-buffer

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Encode behavior encode create new buffer add to buffers add to buffer return true return false input symbol buffer filled? T F

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Insert behavior pack into this buffer pack bottom bits into this buffer, top bits into overflow buffer update length input symbol fills buffer? T F

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Program design zIn an object-oriented language, we can reflect the UML specification in the code more directly. zIn a non-object-oriented language, we must either: yadd code to provide object-oriented features; ydiverge from the specification structure.

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. C++ classes Class data_buffer { char databuf[databuflen]; int len; int length_in_chars() { return len/bitsperbyte; } public: void insert(data_buffer,data_buffer&); int length() { return len; } int length_in_bytes() { return (int)ceil(len/8.0); } int initialize();...

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. C++ classes, cont’d. class data_compressor { data_buffer buffer; int current_bit; symbol_table table; public: boolean encode(char,data_buffer&); void new_symbol_table(symbol_table); int flush(data_buffer&); data_compressor(); ~data_compressor(); }

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. C code struct data_compressor_struct { data_buffer buffer; int current_bit; sym_table table; } typedef struct data_compressor_struct data_compressor, *data_compressor_ptr; boolean data_compressor_encode(data_compressor_ptr mycmptrs, char isymbol, data_buffer *fullbuf)...

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Testing zTest by encoding, then decoding: input symbols symbol table encoderdecoder compare result

© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Code inspection tests zLook at the code for potential problems: yCan we run past end of symbol table? yWhat happens when the next symbol does not fill the buffer? Does fill it? yDo very long encoded symbols work properly? Very short symbols? yDoes flush() work properly?