Docsity

CS10 Spring 2018 Final Exam, Exams of Algorithms and Programming

Toggle sidebar
bg1
1
UC Berkeley’s CS10 Spring 2018 Final Exam: Prof. Dan Garcia
_________________________________ __________________________ ___________________________
Your Name (first last) SID Lab TA’s Name
____________________________________ _____________________________________
ç
Name of person on left (or aisle) Name of person on right (or aisle)
è
What’s that Smell? Oh, it’s Potpourri! (2 pts each for 1-6, low score dropped)
Fill in the correct circles & squares completely…like this: ● (select ONE) n (select ALL that apply)
Question 1: Which does NOT make the Genome assembly computing problem difficult? (select ONE)
○ There may be multiple errors in the input strings.
○ The input is only a small view of the genome (100s of characters) but the output is 10,000s of characters.
○ The letters in the genome input are all 26 letters (A-Z), a vast number of possible combinations.
○ The output genome has to have all the errors removed.
○ None of the Above.
Question 2: What was wrong with early versions of the Google self-driving car at 4-way stops? (select ONE)
○ It couldn’t see the stop sign because its photo sensor was too small, so it drove right through!
○ It yielded to the driver on the left (instead of right), since that’s how they drive where the developers live!
○ It kept waiting for human drivers who would inch forward (looking for an advantage), so it’d be stuck there!
○ It had trouble stopping at the right place since the road markings were often obscured, so it would back up!
○ None of the Above.
Question 3: Prof Marti Hearst talked about what device/concept her HCI group helped invent? (select ONE)
○ Pinch and Zoom (or similar mobile app technology that lets you change the size of an image with 2 fingers)
○ Google Glass (or similar camera + computer + display eyewear technology to record your world while out)
○ Faceted Navigation (or similar web technology that lets you “prune” down what you want when searching)
○ Amazon Alexa (or similar technology that lets you interact with a computer through speech and audio)
○ None of the above
Question 4: What was one memorable moment from the Alumni Panel? (select ONE)
○ The alumnus from Amazon talked about the fun of programming drones to do aerial package delivery.
○ The alumnus from Apple talked about their new “spaceship” campus and getting lost once inside it!
○ The alumnus from Facebook talked about how fun it was watching Mark Zuckerberg testify before congress!
○ The alumnus from GradeScope talked about the fun working for a small startup located so close to Cal!
○ None of the above
Question 5: What is the Halting Problem? (select ONE)
○ It was used to prove that not all problems are decidable.
○ It was one of a family of NP-complete problems; solve one efficiently, and you can solve them all!
○ It was the problem that was recently solved (to great acclaim), proving that P=NP once and for all!
○ It was the occurrence of “forever” blocks in Snap! code that prevent programs from stopping, or “halting”.
○ None of the above
Question 6: What is 4616 divided by 128 written in Binary? (select ONE)
○
○
○
○
○
○
○
○
○
02
12
102
112
1002
1012
1102
1112
None of these
pf3
pf4
pf5

Partial preview of the text

Download CS10 Spring 2018 Final Exam and more Exams Algorithms and Programming in PDF only on Docsity!

UC Berkeley’s CS10 Spring 2018 Final Exam: Prof. Dan Garcia


Your Name (first last) SID Lab TA’s Name


ç Name of person on left (or aisle) Name of person on right (or aisle) è

What’s that Smell? Oh, it’s Potpourri! ( 2 pts each for 1- 6 , low score dropped)

Fill in the correct circles & squares completely…like this: ● (select ONE) n (select ALL that apply)

Question 1: Which does NOT make the Genome assembly computing problem difficult? (select ONE)

○ There may be multiple errors in the input strings.

○ The input is only a small view of the genome (100s of characters) but the output is 10,000s of characters.

○ The letters in the genome input are all 26 letters (A-Z), a vast number of possible combinations.

○ The output genome has to have all the errors removed.

○ None of the Above.

Question 2 : What was wrong with early versions of the Google self-driving car at 4 - way stops? (select ONE)

○ It couldn’t see the stop sign because its photo sensor was too small, so it drove right through!

○ It yielded to the driver on the left (instead of right), since that’s how they drive where the developers live!

○ It kept waiting for human drivers who would inch forward (looking for an advantage), so it’d be stuck there!

○ It had trouble stopping at the right place since the road markings were often obscured, so it would back up!

○ None of the Above.

Question 3: Prof Marti Hearst talked about what device/concept her HCI group helped invent? (select ONE)

○ Pinch and Zoom (or similar mobile app technology that lets you change the size of an image with 2 fingers)

○ Google Glass (or similar camera + computer + display eyewear technology to record your world while out)

○ Faceted Navigation (or similar web technology that lets you “prune” down what you want when searching)

○ Amazon Alexa (or similar technology that lets you interact with a computer through speech and audio)

○ None of the above

Question 4 : What was one memorable moment from the Alumni Panel? (select ONE)

○ The alumnus from Amazon talked about the fun of programming drones to do aerial package delivery.

○ The alumnus from Apple talked about their new “spaceship” campus and getting lost once inside it!

○ The alumnus from Facebook talked about how fun it was watching Mark Zuckerberg testify before congress!

○ The alumnus from GradeScope talked about the fun working for a small startup located so close to Cal!

○ None of the above

Question 5 : What is the Halting Problem? (select ONE)

○ It was used to prove that not all problems are decidable.

○ It was one of a family of NP-complete problems; solve one efficiently, and you can solve them all!

○ It was the problem that was recently solved (to great acclaim), proving that P=NP once and for all!

○ It was the occurrence of “forever” blocks in Snap! code that prevent programs from stopping, or “halting”.

○ None of the above

Question 6: What is 4616 divided by 128 written in Binary? (select ONE)

02 12 102 112 1002 1012 1102 1112 None of these

Question 7 : We put the Fun in Functional Programming… ( 8 = 2+2+ 2 + 2 pts) SID: ______________ Consider the following two blocks and setup code: a) We’re now to going to zoom in on pixels affected by calls to Fun ; the sprite always starts in the lower left facing right, and the pen is in the center of the sprite. Your job is to shade in (completely!) all the pixels that will be colored in after calls to Fun with length set to 2 , 4 and 8 ; don’t worry about drawing the sprite at the end. Clarification: if the sprite were at (0,0) and moved 4 steps to the right, it would be at (4,0) and all pixels along the line from (0,0) through (4,0) would be shaded; 5 pixels in total. After the call to Fun ( 2 ) After the call to Fun ( 4 ) After the call to Fun ( 8 ) b) Could Fun be rewritten iteratively? (select ONE)

○ Yes, and in fact any recursive procedure can be written iteratively.

○ Yes, and it’s fairly common to be able to write recursive solutions iteratively, but not always.

○ Yes, but it’s fairly rare to be able to write recursive solutions iteratively, Most of the time you can’t.

○ No because it’s a command. Had it been a reporter or a predicate, we would have been able to do it.

○ No; it’s one of the rare cases of recursive solutions that can’t be written iteratively. Most of the time you can.

○ No; it’s fairly common not to be able to rewrite recursive solutions iteratively. Sometimes you can, though.

○ No; you can never rewrite recursive solutions in an iterative manner.

Question 9 : What do tablets eat for dinner? iPad Thai … ( 28 = 2*9+10 pts) Instead of a paper final exam for BJC, we decide to use tablet computers, with each of the N problems printed on separate digital “page” (screen). On each page, there’s a field for the answer and a submit button, which when clicked shows the next problem or a “ You’re done! ” screen if they’ve answered all the questions. All students start on page 1, and there’s no way to skip around or go back. When time is up, if the student is still working on a question, the system automatically clicks submit for them. The system records four pieces of information into a database ( DB ) each time submit is clicked; here’s an example that was recorded for a 2- question exam. Note that student 999 99999 fell asleep during question 1, so the system submitted it for them at the end of the exam. All the times in “Seconds since the exam started” will always be in chronological order. Unique student ID Seconds since the exam started Question # Auto-graded score for that question 12345678 60 1 9 11111111 100 1 10 11111111 110 2 5 12345678 260 2 4 99999999 600 1 2 a) Which of the following could be answered by analyzing only the data in DB after the exam is finished? (select ALL that apply)

☐ How many students saw the “You’re done!” screen after they finished the exam.

☐ The number of questions on the exam.

☐ The number of different students who took the exam.

☐ The highest overall score any student achieved.

b) Somehow the first column (Unique student ID) gets corrupted (lost). If we didn’t care about the actual student ID, but only that each student had a different ID that was consistent throughout the DB , when are we guaranteed to be able to recreate the first column using only the other values in DB? (select ALL that apply)

☐ When there is only one student

☐ When no student finishes the first question

☐ When only one student finishes the first question before time is up (i.e., clicked submit themselves)

☐ When exactly two students finish the first question before time is up (i.e., clicked submit themselves)

☐ When no two students are ever on the same question at the same moment in time (except the first)

c) Assume the first column is fine, but now the third column (Question #) gets corrupted (lost). We want to recreate it using only the values in the “Unique Student IDs” column in the DB. That is, assuming you pulled out the first column in DB as a list called SIDs , the following function should return the third column as a list. Fill in the grid below to put up to 6 lines of python into our code on the left AND tell us where to indent the def SIDs_to_questions(SIDs): D={} questions = [] for SID in SIDs: return questions Line number Indent 1 2 3 4 5 6 A B C D E if SID in SIDs: (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ if SID in questions: (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ if SID in D: (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ questions.append(SID) (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ questions.append(D[SID]) (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ questions.append(SIDs) (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ questions.append(D[SIDs]) (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ questions.append(D) (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ D[SID] += 1 (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ D[SID] - = 1 (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ D[SID] = 1 (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ else: (^) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○

A B C D E

lines. Write the code in the area on the left (as a backup). You might not need all 6 lines, and if a command is not used, leave its row blank.

Question 10 : Would you like another pie[1:3]? ( 18 = 2*9 pts) a) We recreated a script of playing in the interpreter, but we may have gotten some of it wrong. For each response, indicate if it is correct, and if it’s not, what the right answer should be.

S = "1234" S[1:3]

" 123 " ç ○ Correct! ○ "23" ○ "12" ○ Error ○ Infinite Loop

>>> S+S

"2468" ç ○ Correct! ○ 2468 ○ "12341234" ○ Error ○ Infinite Loop

"3" in S

True ç^ ○ Correct! ○ False ○ Error ○ Infinite Loop

>>> S[2]="0"

1034 ç ○ Correct! ○ "1034" ○ 1204 ○ "1204" ○ Error ○ Infinite Loop

[x+1 for x in range(4) if x != 2]

[3,4,5] ç ○ Correct! ○ [1,2,4] ○ [1,2,4,5] ○ [2,4,5] ○ Error ○ None of these

def mystery(word): if word[0] in "aeiou": return word+"ay" else: return mystery(word[len(word)-1] + word[0:len(word)-1])

mystery("school") "schoolay"

Correct! "oolay"^ "oolschay"^ "loohcs"^ "loohcsay"^ "olschoay"^ Error Infinite Loop

mystery("sky") "skyay"

Correct! "yay"^ "yskay"^ "yks"^ "yksay"^ Error Infinite Loop b) Assume for this problem that mystery was given a word with many characters, and returned successfully. What is its running time (as a function of the length of word )? You may also assume that slicing, concatenation and determining length are constant-time operations. (select ONE for each side)

Constant Logarithmic Linear Quadratic Cubic Exponential Reasonable Time Not Reasonable Time