0

I have two algorithms.

A. Solves problem in 2^n seconds.

B. Solves problem in n^2 + 1,000,000 seconds.

How can I inductively prove that B is faster than A.

I'm told that 2^n > 2n+1 for n>2 might be useful for this problem. I've been cracking my head and can't solve this problem. Thanks.

"n" is equivalent to the size of the program.

EDIT: For all n > 19.

SOLUTION:

Premise: n^2 + 1,000,000 < 2^n

Basis:
n = 20
1000400 < 1048576 TRUE

Induction:

(n+1)^2 + 1000000 > 2^(n+1)
n^2 +2n +1 +1000000 > 2^(n+1)
Apply 2^n > 2n + 1
n^2 + 1000000 > 2^(n+1)

This last line implies that B is always bigger than A.

amorimluc
  • 1,661
  • 5
  • 22
  • 32

3 Answers3

2

B will only be faster if n > 19.9321. If you don't need the actual work, then here is where I got the answer from.

For any numbers less than 19.9321, then A will be faster.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
Holden Lewis
  • 387
  • 3
  • 18
2

As you said the base case is proven. ie k^2<2^k for k>=5

For the induction, let us assume that

k^2<2^k

We need to prove that

(k+1)^2<2^(k+1)

(k+1)^2 = k^2 + 2k + 1 < 2^k + 2k + 1

We know that (k-1)^2>=0. thus k^2>=2k-1

2^k + 2k + 1 = 2^k + 2k -1 + 2 <= 2^k + k^2 + 2 < 2^k + 2^k +2= 2^(k+1) + 2

Argh, i feel like im almost there. any help?

smk
  • 5,340
  • 5
  • 27
  • 41
  • Induction involves proving for an initial value before moving to k, k+1. This is not included in the answer. – questzen Feb 20 '13 at 04:24
  • Yes, typically prove for 1, assume for k, and deduce for k+1. MI works when the statement is valid for all natural numbers. So applying the logic of 2^n > n^2 wont work! – questzen Feb 20 '13 at 04:32
  • The base would be n = 20. The induction step is the hard part. Would you mind adding the intermediate steps (including when you use the induction hypothesis)? – amorimluc Feb 20 '13 at 04:34
  • Why is the base case n=20, doing some mental calculations i can see that k^2<2^k for k>=5 – smk Feb 20 '13 at 04:35
  • Because it's n^2 + 1,000,000. B is only faster when n > 19. – amorimluc Feb 20 '13 at 04:37
  • I think I got the answer. I'll accept your answer because it got me started in the right direction. Thanks. – amorimluc Feb 20 '13 at 04:48
  • @amorimluc Can you paste your answer as well.. Just not able to get the final step in here.. Thanks for the voetup – smk Feb 20 '13 at 04:52
1

Python as a calculator:

>>> n = 20
>>>
>>> 2**n
1048576
>>> n**2 + 1000000
1000400
>>>
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328