算法设计与分析作业答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

CS330:Introduction To Algorithm Spring2014

Lecture2:Asymptotic Analysis

TF:Xianrui Meng Scribes:Raman Bahdanouski,Ellie Vial

Exercise1

Suppose you have algorithms with thefive running times listed below.How much slower do each of these algorithms get when you(a)double the input size,or(b)increase the input size by one?

1.n2;

2.n3;

3.100n2;

4.nlog(n);

5.2n;

Solution

For doubling the input:

1.f(n)=n2;f (2n)=4n

2.;So the running time of the algorithm gets4times slower.

2.f(n)=n3;f (2n)=8n

3.;So the running time of the algorithm gets8times slower.

3.f(n)=100n2;f (2n)=400n2.;So the running time of the algorithm gets4times slower.

4.f(n)=nlog(n);f (2n)=2n∗log(2n)=2n∗(log(n)+log(2))=2n∗log(n)+2n∗log(2).;So the running

time of the algorithm increases by2n∗log(n)+2n∗log(2).

5.f(n)=2n;f (2n)=22n;f(2n)−f(n)=22n−2n=(2n)∗(2n−1);So the running time of the algorithm

gets slower by the factor of(2n−1).

For increasing the input by one:

1.f(n)=n2;f (n+1)=n2+2n+1.;So the running time of the algorithm increases by2n+1.

2.f(n)=n3;f (n+1)=n3+3n2+3n+1.;So the running time of the algorithm increases by3n2+3n+1.

3.f(n)=100n2;f (n+1)=100(n2+2n+1).;So the running time of the algorithm increases by

100(2n+1).

4.f(n)=nlog(n);f(n+1)=(n+1)∗log(n+1);f(n+1)−f(n)=(n+1)∗log(n+1)−nlog(n)=

n∗log(n+1)+log(n+1)−nlog(n)=log(n+1)+n∗(log(n+1)−log(n));So the running time increases by log(n+1)+n∗(log(n+1)−log(n)).

5.f(n)=2n;f (n+1)=2n+1=2∗2n;So the running time of the algorithm doubles.

2-1

2-2Lecture 2:Asymptotic Analysis Exercise 3

Take the following list of functions and arrange them in ascending order of growth rate.That is,if function g(n)immediately follows function f(n)in your list,it should be the case that f(n)is O(g(n)).

•f 1(n )=n 2.5

•f 2(n )=√2n

•f 3(n )=n +10

•f 4(n )=10n

•f 5(n )=100n

•f 6(n )=n 2log (n )

Solution

We can start approaching this problem by putting f 4and f 5at end of the list,because these functions are exponential and will grow the fastest.f 4

相关文档
最新文档