Beruflich Dokumente
Kultur Dokumente
NAME: ____________________________SOLUTIONS____________________________________
RUID:___________________________________________________________________________
Electronic Devices are not permitted during the quiz. These include but are not restricted to calculators,
computers and cell phones.
No communication between students or anyone outside of class is permitted during the quiz.
Textbooks, notes and any other written materials are not permitted during the quiz.
1. In each blank, write the letter of the formula that most closely provides the number of iterations
performed by the corresponding loop. Ignore any requirement to use a ceiling or floor function.
Note that an option may be used zero or more times (i.e. once, more than once, not at all).
A) lg(x0 a)
B) lg(a - x0)
C) lg(a)
D) lg(x0)
E) lg(x0 / a)
F) lg(a / x0)
G) logx0(a)
H) loga(x0)
I) lg(logx0(a))
J) lg(loga(x0))
K) loga(x0)/lg(a)
L) a - x0
M) logx0(a)/lg(a)
N) logx0(a)/lg(x0)
O) x0 + a
P) x0 a
Q) -lg(logx0(a))
R) -lg(loga(x0))
S) x0 ^ a
T) a ^ x0
U) -logx0(a)/lg(a)
V) -logx0(a)/lg(a)
W) x0
X)
4 points each blank
_____P______ a)
x
x0
while x > a
x
x - 1
end
where:
x0 and a are integers
a < x0
first iteration: x0 - 1
second iteration: (x0 1) 1 = x0 - 2
third iteration: ((x0 1) 1) 1 = x0 - 3
i-th iteration: x0 i 1 = x0 i
when does it stop?
_____F______ b)
x
x0
while x < a
x
2x
end
x0 i
i
i
i
a
a - x0
(a - x0)
x0 a
where:
x0 and a are real numbers
0 < x0 < a
first iteration: x0 2
second iteration: (x0 2) 2 = x0 22
third iteration: ((x0 2) 2) 2 = x0 23
i-th iteration: x0 2i
when does it stop?
x0 2i a
2i a / x0
i lg(a / x0)
_____E______ c)
x
x0
while x < a
x
x / 2
end
where:
x0 and a are real numbers
0 < a < x0 < 1
first iteration: x0 / 2
second iteration: (x0 / 2) / 2 = x0 / 22
third iteration: ((x0 / 2) / 2) / 2 = x0 / 23
i-th iteration: x0 / 2i
when does it stop?
_____I_____ d)
x
x0
while x < a
x
x2
end
x0 / 2i a
x0 2-i a
2-i a / x0
-i lg(a / x0)
i -lg(a / x0)
i -(lg(a) - lg(x0))
i lg(x0) - lg(a)
i lg(x0 / a)
where:
x0 and a are real numbers
1 < a < x0
first iteration: x0 ^ 2
second iteration: (x0 ^ 2) ^ 2 = x0 ^ 22
third iteration: ((x0 ^ 2) ^ 2) ^ 2 = x0 ^ 23
i-th iteration: x0 ^ 2i
when does it stop?
x0 ^ 2i a
2i logx0(a)
i lg(logx0(a))
_____Q______ e)
x
x0
while x > a
x
end
where:
x0 and a are real numbers
1 < a < x0
first iteration:
= x0 ^ (1/2)
second iteration: (x0 ^ (1/2)) ^ (1/2) = x0 ^ (1/22)
third iteration: ((x0 ^ (1/2)) ^ (1/2)) ^ (1/2) = x0 ^ (1/23)
i-th iteration: x0 ^ (1/2i)
when does it stop?
x0 ^ (1/2i)
1/2i
2i
i
i
i
a
logx0(a)
1/logx0(a)
lg(1/logx0(a))
lg(1)-lg(logx0(a))
-lg(logx0(a))
2. Find the least integer n such that f(x) is O(xn) for each of these functions. If no such n is
possible, write Impossible.
2 points each blank
______4______ a) f(x) = 2x2 + x3 log x
2x2 + x3 log x 2x4 + x4 = 3x4
(C = 3, k = 0)
(C = 4, k = 1)
(C = 3, k = 1)
for large x
for large x
for large x
x + x = 2x
______0______ i) f(x) =
= x(1/4
1/3)
______6______ j) f(x) = x5 (
= x(5
for large x
+ 1/2)
= x-1/12 x0
for large x
+ 1/x)
+ x(5
- 1)
= x5.5 + x4
3. Recall that to establish a big- relationship, we find C and k such that f(x) C g( )
for x > k. Assume C, k and x are real numbers. For each of the following blanks, write True if
the given C and k establish a big-O relationship. Otherwise, write False.
a) f(x) = x + 0.5,
f(x) = (x)
____True_____
C = 1, k = 1
____True_____
C = 0.5, k = 1
____False____
C = 1.5, k = 3
____True_____
C = 0.1, k = 0
x
1
2
3
4
5
6
7
x + 0.5
1.5
2.5
3.5
4.5
5.5
6.5
7.5
b) f(x) = x2 + x,
C = 0.1
0.1
0.2
0.3
0.4
0.5
0.6
0.7
C = 0.5
0.5
1
1.5
2
2.5
3
3.5
C = 1
1
2
3
4
5
6
7
C = 1.5
1.5
3
4.5
6
7.5
9
10.5
f(x) = (x2)
____False____
C = 2, k = 0
____False____
C = 2, k = 1
____False____
C = 2, k = 2
____True_____
C = 0.5, k = 2
x2
0
0.25
1
2.25
4
6.25
x
0
0.5
1
1.5
2
2.5
c) f(x) = 2x + 2x,
x2 + x
0
0.75
2
3.75
6
8.75
C = 0.5
0
0.25
0.5
1.125
2
3.125
C = 2
0
0.5
2
4.5
8
12.5
f(x) = (2x)
____True_____
C = 1, k = 1
____False____
C = 2, k = 1
____False____
C = 2, k = 2
____True_____
C = 0.5, k = 2
2x
1
1.414
2
2.828
4
5.657
C = 0.5
0.5
0.707
1
1.414
4
2.828
x
0
0.5
1
1.5
2
2.5
2x
0
1
2
3
4
5
2x + 2x
1
2.414
4
5.828
8
10.657
C = 2
2
2.828
4
5.657
8
11.314
d) f(x) = lg(x) + 4,
____True_____
C = 1, k = 1
____True_____
C = 1, k = 16
____False____
C = 2, k = 16
____True_____
C = 1, k = 256
x
1
2
4
8
16
32
lg(x)
0
1
2
3
4
5
e) f(x) = x! + 2x,
lg(x)+4
4
5
6
7
8
9
C = 1
0
1
2
3
4
5
f(x) = (x!)
C = 2
0
2
4
6
8
10
____True_____
C = 1, k = 1
____True_____
C = 1/4, k = 2
____True_____
C = 0.5, k = 4
____False____
C = 2, k = 0
x
0
1
2
3
4
5
f)
f(x) = (lg(x))
2x
1
2
4
8
16
32
x!
1
1
2
6
24
120
f(x) = 7 + 1/x,
x! + 2x
2
3
6
14
40
152
C = 1/4
0.25
0.25
0.5
1.5
6
30
C = 0.5
0.5
0.5
1
3
12
60
C = 1
1
1
2
6
24
120
C = 2
2
2
4
12
48
240
f(x) = (1)
____True_____
C = 7, k = 0
____True_____
C = 7, k = 1
____False____
C = 8, k = 0
____False____
C = 8, k = 1
x
0.5
1
2
1/x
2
1
2
7 + 1/x
9
8
7.5
C = 7
7
7
7
C = 8
8
8
8
4. What is the effect in the time required to solve a problem when you increase the size of the input
from n to 2n, assuming that the number of milliseconds the algorithm uses to solve the problem
with input size n is each of the quantities expressed below? Let W1 denote the runtime with input
size 2n and let W0 denote the runtime with input size n. In each blank, write the corresponding
letter from the table below. Note that an option may be used zero or more times (i.e. once, more
than once, not at all).
A) W1 - W0 = 0
B) W1 - W0 = 1
C) W1 - W0 = 2
D) W1 - W0 = n
E) W1 - W0 = 2n+1
F) W1 - W0 = n2
G) W1 - W0 = lg((1+lg(n))/lg(n)
H) W1 - W0 = lg(1+lg(n))
I) W1 - W0 = lg(n)
J) W1 - W0 = lg(n+1) lg(n)
K) W1 / W0 = 2
L) W1 / W0 = 4
M) W1 / W0 = 2n
N) W1 / W0 = 2n+1
O) W1 / W0 = lg(n)
P) W1 / W0 = 2n
Q) W1 / W0 = n2
R) W1 / W0 = lg(n2)
S) W1 / W0 = 2 + 2/lg(n)
T) W1 / W0 = 2 + lg(n)
U) W1 / W0 = 2 lg(n)
3 points each blank
_____A_____ a) 2
2 2 = 0
_____B_____ b) lg n
lg 2n lg n = (lg 2 + lg n) lg n = lg 2 = 1
___D or K__ c) n
2n n = n;
2n / n = 2
_____K_____ d) 2n
2(2n) / 2n = 4n / 2n = 2
_____S_____ e) n lg n
(2n lg 2n) / (n lg n) =
=
=
=
=
(2 lg 2n) / lg n
(2(lg 2 + lg n)) / lg n
(2(1 + lg n)) / lg n
(2 lg n + 2) / lg n
2 + 2/lg n
_____L_____ f) n2
(2n)2/n2 = 4n2/n2 = 4
_____P_____ g) 2n
22n / 2n = (2n2n) / 2n = 2n