28.08.2013 Views

Computer Science 124: Problem Set 1

Computer Science 124: Problem Set 1

Computer Science 124: Problem Set 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Collaborators<br />

<strong>Computer</strong> <strong>Science</strong> <strong>124</strong>: <strong>Problem</strong> <strong>Set</strong> 1<br />

Christian Anderson<br />

February 11, 2013<br />

I collaborated with Boom the Thunder Dragon on problem 4.<br />

1<br />

No solution released. I include this section so that the example L ATEX is realistic.<br />

2<br />

No solution released. I include this section so that the example L ATEX is realistic.<br />

3<br />

No solution released. I include this section so that the example L ATEX is realistic.<br />

4<br />

For this problem, I will use the following two definitions:<br />

4.1<br />

• Definition of O: f is O(g) when there exist a positive real number c and a positive<br />

integer N such that for all n > N, f(n) ≤ cg(n).<br />

• Definition of o: f is o(g) when<br />

f(n)<br />

lim<br />

n→∞ g(n)<br />

Let f1(n) = n. We claim that f1(2n) is O(f1(n)). Let c = 2 and let N be any positive<br />

integer. For all n > N, f1(2n) = 2n ≤ 2n = cf1(n).<br />

1<br />

= 0.


4.2<br />

Let f2(n) = 2 n . We claim that f2(2n) is not O(f2(n)). We give a proof by contradiction.<br />

Suppose that f2(2n) is O(f2(n)). Then there exist c and N satisfying the above definition.<br />

This gives that for all n > N, 2 2n ≤ c·2 n . Dividing both sides by 2 n gives that for all n > N,<br />

2 n ≤ c. This is a contradiction.<br />

4.3<br />

We know that there exist (c1, N1) such that for k > N1, f(k) ≤ c1g(k). Similarly, there<br />

exist (c2, N2) such that for ℓ > N2, g(ℓ) ≤ c2h(ℓ). Let N = max(N1, N2). Then for n > N,<br />

f(n) ≤ c1g(n) and g(n) ≤ c2h(n). Composing these equations gives that for n > N,<br />

f(n) ≤ c1c2h(n). Thus f(n) is O(h(n)).<br />

4.4<br />

This statement is false. We give a counterexample. Let f(n) = n. Let g(n) be defined<br />

differently on the even and odd positive integers. For even n, g(n) = 1. For odd n, g(n) = n2 .<br />

An alternative way to state this is<br />

<br />

1 for even n<br />

g(n) =<br />

n2 for odd n.<br />

We see that f(n) is not O(g(n)) because n is not O(1). Likewise, g(n) is not O(f(n)) because<br />

n 2 is not O(n).<br />

4.5<br />

This statement is true. We give a proof. Suppose that f is o(g). Then we know that<br />

f(n)<br />

lim<br />

n→∞ g(n)<br />

The definition of the limit (available on Wikipedia and elsewhere) lets us re-write the above<br />

equation as the following: for any ɛ > 0, there exists C such that for all x > C, |f(x)/g(x)| <<br />

ɛ. Choose some c > 0. Then the previous statement implies that there exists a positive<br />

integer N such that for all x > N, f(x) < cg(x). Thus f is O(g).<br />

2<br />

= 0.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!