

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans
http://www.cs.virginia.edu/cs216 UVa CS216 Spring 2006 - Lecture 15: Numbers 2
Menu
UVa CS216 Spring 2006 - Lecture 15: Numbers 3
Fighting Finalizers
Problem due to Paul Tyma, Google
x a (^) b x = NULL; a.finalize (); b.finalize ();
UVa CS216 Spring 2006 - Lecture 15: Numbers 4
Finality?
x a (^) b
class A { B p; }
class B { A r; void finalize() { r.p = this; }
a = new A(); a.p = new B(); a.p.r = a; x = a; a.p = NULL; GC – b.finalize () a.p.toString () Problem due to Paul Tyma, Google
UVa CS216 Spring 2006 - Lecture 15: Numbers 5
Encoding
UVa CS216 Spring 2006 - Lecture 15: Numbers 6
Lempel-Ziv-Wench (LZW)
UVa CS216 Spring 2006 - Lecture 15: Numbers 7
LZW Encoding Algorithm def LZWEncode (s): w = “”; res = “”; dictionary.initialize() # code for each alphabet symbol foreach k in s: if dictionary.contains (w + k): w = w + k; else
dictionary.append (w + k) res = res + dictionary.find (w) w = k;
w is already in dictionary: no need to send dictionary to decode! UVa CS216 Spring 2006 - Lecture 15: Numbers 8
Compression Bake-off Declaration of Independence Original 8586 Huffman (PS4) 5123 (60%) Compress (LZW) 4441 (52%) Gzip (not LZW) 3752 (44%) Random Characters Original 10000 Huffman (PS4) 9517 Compress (LZW) 10000 (“file unchanged”) Gzip (not LZW) 8800 This is quite surprising!
UVa CS216 Spring 2006 - Lecture 15: Numbers 9
GIF
How is GIF different from JPEG? UVa CS216 Spring 2006 - Lecture 15: Numbers 10
Lossy/Lossless Compression
UVa CS216 Spring 2006 - Lecture 15: Numbers 11
What’s wrong with GIF?
PNG (“PNG’s Not GIF”) UVa CS216 Spring 2006 - Lecture 15: Numbers 12
Representing Numbers