COS 109: Problem Set 5

Thu Oct 23 17:34:20 EDT 2014

Due 5:00 PM, Wednesday, Nov 5, in the box outside Room 311, CS building, or in class. Answers need not be long, merely clear so we can understand what you have done. Please submit typed material, not hand-written, if at all possible, and keep a copy for yourself just in case something goes astray. Thanks.

Collaboration policy for COS 109: Working together to really understand the material in problem sets and labs is encouraged, but once you have things figured out, you must part company and compose your written answers independently. That helps you to be sure that you understand the material, and it obviates questions of whether the collaboration was too close.

You must list any other class members with whom you collaborated.

 

1. A Small Matter of Programming

(a) The following Javascript function is supposed to count down from the initial value of n to 1, printing the values, then print "Boom!" at the end. That is, countdown(3) should print "3, 2, 1, Boom!". Unfortunately, it doesn't work. Find and fix the errors. (This is a question about logic, not about syntax, but if you put the code into a file and run it, you can be sure that it works.)

	function countdown(n) {
	   i = 0
	   while (i > n) {
	      i = i - 1
	      print n
	      print "Boom!"
	   }
	}

(b) This program is supposed to display the powers of 2 from 2^0 to 2^10 inclusive, using the function Math.pow(n, m), which computes n^m. Sadly, the program doesn't work. Fix the errors, which you can do without adding or deleting any lines. (This question is about logic and numeric values, not syntax; assume the syntax is correct.)

    n = 1
    while (n < 1024) {
        print Math.pow(n, 2)
        n = n + 2
    }

 

2. File Systems

Suppose that part of the file system on a computer looks like this, where names beginning with D are directories (indicated by circles), and names beginning with F are files (indicated by squares):

That is, directory D1 contains directories D2, D3 and D4 and files F1 and F2; directory D1/D2 contains directory D3 and files F3 and F4; directory D1/D2/D3 contains file F4; and so on.

Assume that no other files are involved, the files have the given sizes in bytes, directories occupy one disk block each, and all disk blocks are 1024 bytes long. Each question assumes that reading a file or directory into RAM begins by reading the block that contains directory D1 and works down the hierarchy until the desired information is found, reading only blocks that must be read. No directory is read more than once in this process. Be careful to distinguish between files and directories -- a directory contains the names of files and other information about them, but not their contents.

(a) How many disk blocks in total are used by these directories and files?

(b) How many blocks would the file system have to read from disk (including reading D1) to read all the blocks of file D1/F1 into RAM?

(c) How many blocks must be read from disk to read all the blocks of file D1/D2/D3/F4 into RAM?

(d) How many blocks must be read from disk to decide whether D1/F1 and D1/F2 have exactly the same contents?

(e) How many blocks must be read from disk to determine whether or not a file named D1/D2/D4/D6/F4 exists?

(f) Most files waste some space at the end because their size isn't an integral number of blocks. Which file wastes the most, and how much?

(g) Which file wastes the least, and how much?

 

3. Yet More Numbers

(a) Suppose that a 1 micron integrated circuit technology formerly produced 6-inch wafers and has since been improved to produce 12-inch wafers.
    (i) If there are 1,000,000 transistors on a 6-inch wafer and everything else remains the same, about how many transistors would there be on a 12-inch wafer?
    (ii) Suppose that in addition to bigger wafers, the line width (feature size) has also been improved, from 1 micron to 25 nanometers. How many transistors would there be on a 12-inch wafer with 25 nm technology?

(b) An article in the Guardian (12/1/13) says that GCHQ (the British equivalent of the NSA) had tapped 200 fiber optic cables, each running at 10 gigabits per second.
    (i) Approximately how many petabytes per day would this amount to?
    (ii) The article says that this would be "equivalent to sending all the information in all the books in the British Library 192 times every 24 hours." From this odd factoid, estimate approximately how many books there are in the British Library. State your assumptions clearly.

(c) On 12/9/09, the Wall Street Journal said that the Nook ebook reader has 2 GB of memory, "enough to hold about 1,500 digital books." On 12/10/09, the NY Times said that a zettabyte "is equivalent to 100 billion copies of all the books in the Library of Congress." From these two statements, estimate approximately how many books there are in the Library of Congress. State your assumptions clearly.