15-110 Spring 2011 Quiz 3
20 minutes
SHOW YOUR WORK. Correct answers without supporting work will
not receive credit.
For questions saying “in 10 words or less”, we will only grade the first 10
words you write!
1. [30pts; 10 pts each] Indicate what each will print:
x = 5 |
x = 5 |
x = 5 |
2. [40pts; 13 pts each, 1 for breathing] Indicate what each will print:
for
row in range(4): |
def
f(x,y):
|
def
f(s): print
f("abcdefg") |
3. [10pts] In the shotgun algorithm, DNA is split into
small segments, which are sequenced, and then these sequences are reassembled
so the entire original DNA strand is sequenced.
In just a few words, how does the shotgun algorithm know how to place
two sequences next to each other in the re-assembly step?
4. [10pts]
In just a few words, why does the Jeopardy-playing Watson require so much
parallel computing? Couldn’t it get the
same answers without parallel computing?
5. [10 pts; 5 pts each] Indicate what each will print (it is better to reason about these than trace them):
def
f(n): print
f(-192837465) |
def
f(s,t): s="a8b7c6d5e4f3g2h1i0" |
6. Bonus/Optional [5 pts]: What will the following code print? Show your work!
def f(x,y):
w = 0
for z in range(y/2,x/2): w += z/4
return w
def g():
for c in
"abcdefghijklmnopqrstuvwxyz":
if f(ord(c)-ord("a"),0) >
0: return c
return "failed!"
print g()