Sample Problem 3
In this problem you are NOT allowed to use the theorems about BigOh stated in the lecture notes.
Your proof should follow just from the definition of BigOh.
Let
f
(
n
) =
1
10
n
√
n
and
g
(
n
) = 100
n
+ 1000
Prove that
f
(
n
) is
not
O
(
g
(
n
)).
Answer
Proof by contradiction.
Suppose that
f
(
n
) is
O
(
g
(
n
)), i.e.,
∃
N, c >
0 such that
∀
n
≥
N
we have
1
10
n
√
n
≤
c
(100
n
+ 1000)
First we transform a bit the last inequality into an equivalent one:
1
10
n
√
n
≤
c
(100
n
+ 1000)
iff
n
√
n
≤
1000
cn
+ 10000
c
iff
n
(
√
n

1000
c
)
≤
10000
c
This last inequality is contradicted if
n >
1 and
√
n

1000
c >
10000
c
, that is
n >
11000
2
c
2
.
Therefore the statement
∀
n
≥
N
1
10
n
√
n
≤
c
(100
n
+ 1000) is contradicted by taking
n
= max(
N,
1
,
11000
2
c
2
)
(The reason we have 1 there is because our def of BigOh does not require
N, c >
1.)
Sample Problem 4
Analyze the following fragment of code and give a BigOh characterization of its running time (that
is, give the best upper bound on the worstcase running time of the algorithm that you can find).
Explain your analysis.
public static void doWork (int[] arr) {
for (int i=1; i < 10; i++) {
for (int j=0; j < 3*i; j++) {
for (int k=0; k < arr.length; k++) {
System.out.print(i+j+k);
}
}
}
Answer
Let
n
=
arr
.
length
be the size of the input.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 TANNEN
 Algorithms, Data Structures, Analysis of algorithms, Negative and nonnegative numbers, Existential quantification

Click to edit the document details