15110 PRINCIPLES OF COMPUTING EXAM 1A- SPRING 2014
1
[12]_
Name _ANSWERS_ Section _
2
[22]_
Andrew id _
3
[14]_
4
[20]_
5
[26]_
6
[6]_
Directions: Answer each question neatly in the space provided.
Please read each question carefully. You have 50 minutes
15-110 Spring 2014
Programming Assignment 6
due Tuesday, March 4
Overview
Data structures are powerful tools for computer scientists and programmers. They help manage
complexity, promote organization, and allow for the implementation of clever algorithms.
15110 PRINCIPLES OF COMPUTING EXAM 1A FALL 2012
1
_
Name _ Section _
2
_
Andrew id _
3
_
4
_
5
_
6
_
Directions: Answer each question neatly in the space provided.
Please read each question carefully. You have 50 minutes for
this exam. No electronic devic
#function returns True if root is a leaf of a Huffman tree
def is_leaf(root):
#a leaf is a single character string, therefore: type is str, length is 1
if type(root) = str and len(root) = 1:
return True
else:
return False
#function returns True if root is
def int_to_bin_string(n):
if n = 0:
return "0"
s = "
while n > 0:
if n % 2 = 0: # even
ch = "0"
else:
ch = "1"
s = ch + s
n = n / 2
return s
def bin_string_to_int(s):
n = 0
for c in s:
n = n * 2
if c = "1":
n = n + 1
return n
# hex_string_to_bin_string.py
15110 PRINCIPLES OF COMPUTING EXAM 2A SPRING 2014
_
_
4
Directions: Answer each question neatly in the space provided.
Please read each question carefully. You have 50 minutes for
this exam. No electronic devices allowed. Good luck!
2
3
Section _
_
_
5
Na
15110 PRINCIPLES OF COMPUTING EXAM 2B SPRING 2014
_
_
4
Directions: Answer each question neatly in the space provided.
Please read each question carefully. You have 50 minutes for
this exam. No electronic devices allowed. Good luck!
2
3
Section _
_
_
5
Na
15110 Spring 2014
Problem Set 1 - due Friday, January 24 beginning of class
Reading Assignment
Read sections 1.1-1.3 of Chapter 1 of Explorations in Computing and read Chapter 1
of the book Blown To Bits .
Instructions
Type or neatly write the answers to
15-110 Spring 2014
Problem Set 11 - Due Monday April 21, 2014
in class
Reading Assignment
Read Chapter 4 (Needles in the Haystack) of Blown to Bits.
Instructions
Type or neatly write the answers to the following problems.
Please STAPLE your homework befor
15110 Spring 2014
Programming Assignment 3 - due Tuesday, February 4
by 11:59 pm
Note: You are responsible for protecting your solutions to these problems from
being seen by other students both physically (e.g., by looking over your shoulder)
and electron
15110 Spring 2014
Problem Set 5 - due Friday, February 21 in class
Reading Assignment
Read sections 5.1-5.7 in chapter 5 of the textbook Explorations in Computing.
Instructions
Type or neatly write the answers to the following problems.
Please STAPLE your
Sample Answers for Problem Set 3
15110 Fall 2014
1.a. medium
1.b. Any age and bmi such that age < 45 and bmi < 22
1.c.
1.d. def heart_risk(age, bmi):
if age < 45 and bmi < 22:
risk = "low"
elif age < 45 and bmi >= 22:
risk = "medium"
elif age >= 45 and bm
15110Spring2015
PS3Solutions
1.a.high
b.Anypairofvalueswhere e < 4 b i < 2
a 5and 2Forexample,44and21for e
g
m
.
a s
g
and irespectively.
b
m,
c.
d.Thevariableriskwouldbesetto"medium"butnothingwillbeprintedsincethereisno
calltotheprintfunctionwithinthe
import time
# Part 1 solutions
def search(integer_list, key):
for i in range(0, len(integer_list):
if integer_list[i] = key:
return i
return None
timedList = list(range(100, 100000)
def timer():
start = time.time()
search(timedList, 700)
end = time
#=
# debug_part_one.py
#=
# Problem 1
#-
# The following function returns a string that is the
# concatonation of all the strings in a list
# Place your responses to Problem 1 here:
# 1. run time error
# 2. big_string = big_string + string_elem
# 3.
Lab2SampleSolutions15110S15
answers.txt
a. 250integer
b. 3integer
c. 250.0floatingpoint
d. 300000.0floatingpoint
e. 300000integer
f. 90integerPythontakesintoaccountorderofoperations
g. 2.0floatingpoint
h. 0integerthe/meansintegerdivision,so2/3=0
i. 6integ
15110 Homework set 04 Solutions / Fall 2014
1.a f(n) is O(n^3) and g(n) is O(n^2)
1.b f(n)
1.c n_1 can be any integer > 9 and n_2 any integer <= 9
1.d We're only concerned with the growth rates of the functions as their
input increases without bound ("for
15110 Fall 2014
Problem Set 4 - due Friday, September 26 in class
Instructions
Type or neatly write the answers to the following problems.
Please STAPLE your homework before you hand it in.
On the first page of your homework, include your name, andrew ID,
15110 Fall 2014
Problem Set 3 - due Friday, September 19 in class
Reading Assignment
Read Chapter 3 of the book Explorations in Computing .
Instructions
Type or neatly write the answers to the following problems.
Please STAPLE your homework before you han
15-110 Principles of Computing Fall 2014
Problem Set 2 - due Friday, September 12 at the beginning
of class
Reading Assignment
Read sections 2.1-2.4 in chapter 2 of the textbook Explorations in Computing and
read pages 19-42 of chapter 2 of the bookBlown
Sample Answers for Problem Set 1
15110 - Fall 2014
1. Jacquards loom used punched cards to input the patterns to be
weaved by the loom. If there was a hole in the card in a particular
location, then a hook could pass through the card, grasp a thread, and
15110 Fall 2014
Problem Set 1 - due Friday, September 5 beginning of class
Reading Assignment
Read sections 1.1-1.3 of Chapter 1 of Explorations in Computing and read Chapter 1
of the book Blown To Bits .
Instructions
Type or neatly write the answers to t
15110 PRINCIPLES OF COMPUTING EXAM 1A FALL 2012
1
_
Name _ Section _
2
_
Andrew id _
3
_
4
_
5
_
6
_
Directions: Answer each question neatly in the space provided.
Please read each question carefully. You have 50 minutes for
this exam. No electronic devic
15-110 Problem Set 7
1.
a.
b. n1 = 1: f(1) = 1, g(1) = -4
n2 = 5: f(5) = 4.49, g(5) = 20
c. Its possible because a function having a higher rate of growth doesnt mean that the
values of that function are always greater than the other. If g(n) has a higher
Prouin
at1Sltos
dfpitnl_vn:
ern_tee
()
n
onne
riagn:
f i
r
(, +)
0 1
f=:
ii%2=)
( 0
rn
it
p
()
i
Prouin
at2Sltos
dfbidls_tigrn_it:
eul_itsrntigls
(
s
)
t
r
s
=
oitidxagnrn_it)
rls_nenneetigls:
f
i
r
(,l (
0
s
)
tttiglsitidx
rrsrn_its_ne
s
=s +
[
l
]
eu
15-110 Problem Set 3
1.
a.
i.
ii.
iii.
iv.
Bananas and Raisins
Apples and Raisins
Apples and Pears and Raisins
Raisins
b.
c. Apples: (10, 18)
Pears: (10, 13]
Bananas: (-infinity, 10]
Raisins: (-infinity, +infinity)
2.
a. def sum2(list):
sum = 0
a = len(li