CS 1501 Fall 2005 Midterm Exam 2, Exams of Computer Science

The cs 1501 fall 2005 midterm exam 2 for a computer science course. It includes various algorithm and data structure related questions, such as identifying compressible file types, implementing double hashing, explaining bloom filter search operation, estimating space requirements for graph data structures, computing fibonacci numbers, and more. The document also includes instructions for the students and some notes for spring 2006 students.

Typology: Exams

Pre 2010

Uploaded on 09/02/2009

koofers-user-zlp
koofers-user-zlp 🇺🇸

9 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 1501 Fall 2005
Midterm Exam 2
Name____________________________________
1) (1 Point Extra Credit) Consider the following situation. You are interviewing at Google,
Amazon, Microsoft, or Yahoo. You are asked how you would solve a particular algorithm
problem. You don’t have a clue what the best answer should be. According to your
instructor, what one word answer is most likely be correct?
Hashing
2) (15 points)..
a) Of the following file types, identify the one that was most compressible, and second
most compressible, using LZW based on your experiments in assignment 3.
DNA string
.bmp
English text in ASCII
.jpg
.wav
Best Answer: Most = .bmp (uncompressed images usually compress by a factor of 5-10)
and Second Most = English text (which usually compresses by a bout a factor of 2)
Note that DNA appears random to all known compression algorithms and doesn’t
compress at all.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download CS 1501 Fall 2005 Midterm Exam 2 and more Exams Computer Science in PDF only on Docsity!

CS 1501 Fall 2005 Midterm Exam 2 Name____________________________________

  1. (1 Point Extra Credit) Consider the following situation. You are interviewing at Google, Amazon, Microsoft, or Yahoo. You are asked how you would solve a particular algorithm problem. You don’t have a clue what the best answer should be. According to your instructor, what one word answer is most likely be correct? Hashing
  2. (15 points).. a) Of the following file types, identify the one that was most compressible, and second most compressible, using LZW based on your experiments in assignment 3. DNA string .bmp English text in ASCII .jpg .wav Best Answer: Most = .bmp (uncompressed images usually compress by a factor of 5-10) and Second Most = English text (which usually compresses by a bout a factor of 2) Note that DNA appears random to all known compression algorithms and doesn’t compress at all.

b) Assume that you are implementing double hashing. Let h 1 (x) be the primary hash function, and h 2 (x) be the secondary hash function. What is the probe sequence for an element x? The ith probe, i = 1, 2, …, n is (h 1 (x) + (i-1) h 2 (x)) mod n where n is the table size c) Assume that you are implementing a Bloom filter with the k hash functions h 1 , h 2 , …, hk, and a hash table/array H. Explain how to implement a SEARCH/FIND operation. A SEARCH(x) operation returns a Boolean that is true if and only if the key x was previously inserted. H[h 1 (x)] AND H[h 2 (x)] … AND H[hk(x)]

  1. (12 points) In this problem we consider the Fibonacci numbers a) Write a recursive Java, C or C++ function to compute the nth Fibonacci number Fn. See page 52 of the text b) Estimate how long in seconds it would take to compute F 500 running this recursive code on your PC. Show your calculations. Let T(n) be the number of operations to compute Fn. Then 2 T(n-2) < T(n) < 2 T(n-1), so 2250 < T(500) < 2^500. Dividing this by something like 10^9 operations per second gives you some sort of rough estimate that is ridiculously huge. c) Estimate within a factor of two, the number of digits in F 500 if it was written out in binary in the standard way. Show your calculations. 2 Fn-2 < Fn < 2 Fn-1, so 2^250 < F 500 < 2^500. Taking the lg, we get that the number of bits required to epress F 500 is between 250 and 500. d) Write Java, C or C++ code that will compute F 500 in less than a second. Assume that you have an integer type with sufficiently many bits to hold F 500. See page 53 of the text
  1. (15 points) Consider the Move-to-Front List Update compression scheme that you were asked to implement in assignment 3. Recall that that the program read in 16 bits at a time. For simplicity, we will use capital letters here to stand for different 16 bit strings. Assume that the input file looks like: D D B C B A. So the input file consists of 6*16 bits, the first and second 16 bits are equal, and the third and fifth sixteen bits are equal. Assume that initial order of the list from front to back is: A B C D E F …. Note that the order of the items not near the front of the list is not relevant for this question. Give the bit sequence in the compressed file. Identify which bits in the compressed file correspond to each of the six 16- bit sequences in the input file. Assume that the number of bits in the compressed file may be arbitrary (it need not for example be a multiple of 8). 000111 00000 000110 000111 0001 000111 D D B C B A
  1. (8 points) Give the order that the edges are added to the minimum spanning tree using Prim’s (called Priority Search in the book) algorithm starting from vertex s. 17, 7, 1, 5, 14, 22 s
  1. (15 points) Assume that we are computing the edit distance between the words ABBA CAB using the dynamic programming algorithm that we implemented in assignment 4 Fill in the table of edit distances that the algorithm would compute. Explain how to find the edit distance (the fewest number of edits required) to change ABBA into CAB from the table. You need not explain how to find the actual edits/changes. C A B 0 1 2 3 A 1 1 1 2 B 2 2 2 1 B 3 3 3 2 A 4 4 3 3 The edit distance is stored in the bottom right entry.
  2. (15 points) In the Knapsack problem (which is discussed in section 42 of the text, and that we discussed in class) the input consists of n objects with weights w[1] … w[n] and values

Students: Do not write on this page. Total Score: _________________________________

  1. __________________ (1 point extra credit)
  2. a) _________________ (5 points) b)_________________ (5 points) c)_________________ (5 points)
  3. __________________ (10 points)
  4. a) __________________ (3 points) b)__________________ (3 points) c) __________________(3 points) d) __________________ (3 points)
  5. ___________________ (15 points)
  6. ___________________ (5 points)
  7. ___________________ (8 points)
  8. ___________________ (15 points)
  9. ___________________ (20 points)