笔记
这一章基本上就是忽悠大家努力学习算法:算法是一种通过有限步骤的运算来解决计算问题的方式,blabla...算法和数据结构密切相关。算法是一种技术。好的算法可以比差的算法猛的多,好几个数量级,等等。
习题答案
1.1-1
Give a real-world example that requires sorting or a real-world example that requires computing a convex hull.
排序,给班上的学生成绩排序,决定他们的爸妈回去打不打他们的屁股。
计算曲面,游戏或者电影里面用的上吧。
1.1-2
Other than speed, what other measures of efficiency might one use in a real-world setting?
这个问题在公开课上有很好的讨论。空间复杂度(内存和硬盘的占用率),实现方便程度,安全性,容易维护性,等等,都是实际工程需要讨论的。
Rob Pike有一篇C语言编程实践,非常精炼,他认为数据结构才是程序的核心,而非算法,中文版在这里。
1.1-3
Select a data structure that you have seen previously, and discuss its strengths and limitations.
链表,链表的好处在于插入,删除都是O(1)的,当然随机读就不行,是O(n)的。关于链表,我看到linus在网上和人讨论过。这里有2篇文章精妙的讨论了链表作为linux内核的基础数据结构,和怎么通过C语言的特性来减少开销所能做到的:
1.1-4
How are the shortest-path and traveling-salesman problems given above similar? How are they different?
相同之处: 找一条最短的路。
不同之处: 最短路径问题的起点和终点是确定的。邮递员问题不确定,可以任意选择点的顺序。
1.1-5
Come up with a real-world problem in which only the best solution will do. Then come up with one in which a solution that is “approximately” the best is good enough.
前者,我想到的是语音识别技术,如果不能达到90%以上的识别率,那就没什么大用。据说李开复在这个方面做了很多工作。现在的手机和最新的Google Andriod TV都能非常方便的使用语音识别,很牛。
后者,地图导航,在城市里面有很多路,找到差不多最短的路就可以了,反正都能走么。
1.2-1
Give an example of an application that requires algorithmic content at the application level, and discuss the function of the algorithms involved.
额,老答案,GPS导航,最短路径问题。
1.2-2
Suppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of sizen, insertion sort runs in 8n^2 steps, while merge sort runs in 64nlgn steps. For which values of n does insertion sort beat merge sort?
8n^2 = 64nlgn
n = 8lgn
n = 2, 2 < 8
n = 8, 8 < 24
n = 32, 32 < 40
n = 64, 64 > 48
n在32和64之间,后面可以用计算器暴力求解,偷看答案是43。
1.2-3
What is the smallest value of n such that an algorithm whose running time is 100n^2 runs faster than an algorithm whose running time is2^n on the same machine?
100n^2 < 2^n
n = 10, 100*100 < 1024
n = 9, 100*81 > 512
所以n = 10。
问题答案
1-1
Comparison of running times For each function f(n) and time t in the following table, determine the largest sizenof a problem that can be solved in timet, assuming that the algorithm to solve the problem takes f(n) microseconds.
这题是考察美国学生的小学数学计算能力么?太没技术含量啦……
所以我就不做了,嗯
可以到另一位老兄的习题集里面去看
来源:oschina
链接:https://my.oschina.net/u/224285/blog/287217