算法导论第三版第一章习题答案
2013-03-01 15:17
477 查看
1.1-2 除速度外,在真实环境中还可能使用哪些其他有关效率的量度? Other than speed, what other measures of efficiency might one use in a real-world setting?空间,硬件资源等。 1.1-4 前面给出的最短路径与旅行商问题有哪些相似之处?又有哪些不同? How are the shortest-path and traveling-salesman problems given above similar? How arethey different?相似点:找出最短路径不同点:shortest-path 不一定经过所有点,而 traveling-salesman 得经过所有点1.2-2 假设我们正比较插入排序与归并排序在相同机器上的实现。对规模为n的输入,插入排序运行8n2步,而归并排序运行64nlgn步。问对哪些n值,插入排序优于归并排序? Suppose we are comparing implementations of insertion sort and merge sort on the samemachine. For inputs of size n, insertion sort runs in 8n2 steps, while merge sort runs in 64nlg n steps. For which values of n does insertion sort beat merge sort?插入排序的性能优于合并排序也就是:插入排序所用的步数少:所以有:8n2 ≤ 64nlgn ⇒ n < 8lgn 需要解一下这个超越方程,编个程序很容易得到: 2 ≤ n ≤ 43下面是我用Go语言编写的程序:
开立方计算器:http://www.838dz.com/calculator/1633.html另外一个地方看到是下面的,显然不正确。 参考的答案出处:/article/5936624.htmlhttps://docs.google.com/viewer?a=v&q=cache:hu0UWB6qpUgJ:fongfc.files.wordpress.com/2009/10/alg_sol_ch_2.pdf+&hl=zh-CN&gl=cn&pid=bl&srcid=ADGEESj5S_EjsSP4YCrBqM-wg51OMZCD2cE7hUDgpMMxgrR53J8ShQeMWMnDWzPzwFCTmeGDsa4mQCn8QPDNCcT89mXjSGUPz8D4fLIqX7SRvIETC-bqWeuoe9yUog8kpthCYtuyDtY7&sig=AHIEtbSj8XPsoBey-u5H0l1KHNNX_U9vNw
for n:=2;n<50;n++{
if float64(n)<8*math.Log2(float64(n)){
fmt.Println(n)
}else{
break
}
}1.2-3 n的最小值为何值时,运行时间为100n2的一个算法在相同机器上快于运行时间为2[b]n的另一个算法?[/b]原理同上题,可列出如下不等式:100n2 ≤ 2n 解这个不等式(代数法),可求出最小的整数 n=15下面是我用Go语言编写的程序:
for n:=1;n<50;n++{
fmt.Println(n)
if float64(100*n*n)>math.Exp2(float64(n)){
fmt.Println(n)
}else{
break
}
}思考题 1-1 (运行时间的比较) 假设求解问题的算法需要f(n)毫秒,对下表中的每个函数f(n)和时间t,确定可以在时间t内求解的问题的最大规模n。Problems 1-1: Comparison of running timesFor each function f(n) and time t in the following table, determine the largest size n of aproblem that can be solved in time t, assuming that the algorithm to solve the problemtakes f(n) microseconds.lgn 的算法执行时间需要f(n)毫秒,1秒等于1000毫秒,则可以有后面公式:1000/(lgn) <= 1 => 1000 <= lgn => 2^1000 = n
1秒 | 1分钟 | 1小时 | 1天 | 1个月 | 1年 | 1个世纪 | |
lgn | 2^1000 | 2^60000 | 正无穷大 | 正无穷大 | 正无穷大 | 正无穷大 | 正无穷大 |
Sqrt(n) | 10^6 | 4.29E+9 | 1.76E+13 | 9.01E+15 | |||
n | 1000 | 60000 | 3600000 | 86400000 | 259000000 | 31104000000 | 3110400000000 |
nlgn | 141 | 4896 | 204095 | 3.94E+6 | |||
n^2 | 32 | 245 | 1898 | 9296 | 50912 | 177584 | 1775838 |
n^3 | 11 | 40 | 113 | 443 | 638 | 3145 | 14598 |
2^n | 10 | 16 | 22 | 27 | 32 | 35 | 42 |
n! | 7 | 9 | 10 | 12 | 15 | 17 | 18 |
相关文章推荐
- 《算法导论》第一章第一节习题(没有答案)
- 算法导论第五章习题答案(第三版) Introduction to Algorithm
- 算法导论第九章习题答案(第三版) Introduction to Algorithm
- 算法导论第三章习题答案(第三版) Introduction to Algorithm
- 算法导论第八章习题答案(第三版) Introduction to Algorithm
- 算法导论课后习题答案
- 算法导论第三版第二章第一节习题答案
- 算法导论第四章习题答案(第三版) Introduction to Algorithm
- 算法导论第三版第二章第二节习题答案
- 算法导论第二章习题答案(第三版) Introduction to Algorithm
- 算法导论第七章习题答案(第三版) Introduction to Algorithm
- 算法导论第三版第二章第三节习题答案
- 算法导论习题答案(第二章)--自己整理
- 算法导论习题答案(第二章)--自己整理
- 算法导论第15章习题答案
- 【深度学习:21 天实战 Caffe】课后习题参考答案
- apue 习题4.6参考答案
- c++ primer习题6.12答案
- Numerical Computing with MaTLAB 中的工具箱 ncm 以及习题答案和程序下载
- Swift语言基础小习题(包含答案)-只适合菜鸟.