Difference between revisions of "CSC231 Final Exam Solutoins 2012"

From dftwiki3
Jump to: navigation, search
Line 118: Line 118:
 
;; /////////////////////////////////////
 
;; /////////////////////////////////////
  
;; I wrote a python program to count the number of characters in the output: the answer I got was 1606 (I deleted the extra spaces between
+
;;;;;; (note from DT: see answers above code...)
; the dance emoticons on the 10th line. I wrote another program to count the number of bytes in the data section. For this input, I got 818
 
; bytes of memory storage. Storing 1606 characters would require 1606 bytes, but using this compression algorithm the data section of this
 
; program only requiers 808 bytes.  Thus, for this input, the compression factor is 818 / 1616, about %50.
 
; In other words, the data is stored in half the space that would be required to include the full ouput.
 
;
 
; The largest output we can store in 3 bytes is a one character emoticon printed 254 times. This data would require
 
; 3 bytes to store: 254,3,'d'. Thus, the lowest possible value is 3 / (254  * 3) = 0.0039.
 
; Regardless of how many lines of data there are, if they all adhere to these numbers the total compression ratio will always be 0.0039.
 
; I believe that the length of the string is irrelevent. If say, the emoticon text (i.e. 'beer' or 'dance') is very long, say 254
 
; characters, then we have the equation (2 + 252) / (254 * (252 + 2)) = .00393 (about the same). The numerator must increase because we have to spend
 
; 254 bytes to store the 254 character emoticon. So I believe that .0039 is the best compression ratio we can get with this algorithm.
 
; The number 254 is used because bytes can only store the numbers 0-254. The length of string is limited because the length must be stored
 
; in the second byte of our encoding.
 
 
 
  
  

Revision as of 14:47, 20 December 2012

--D. Thiebaut 14:37, 20 December 2012 (EST)



This section is only visible to computers located at Smith College