算法小論——第一章 天之道,損有餘而奉不足……咳咳拿錯稿子了

筆記

這一章基本上就是忽悠你們努力學習算法:算法是一種經過有限步驟的運算來解決計算問題的方式,blabla...算法和數據結構密切相關。算法是一種技術。好的算法能夠比差的算法猛的多,好幾個數量級,等等。html


習題答案

1.1-1

Give a real-world example that requires sorting or a real-world example that requires computing a convex hull.linux

排序,給班上的學生成績排序,決定他們的爸媽回去打不打他們的屁股。git

計算曲面,遊戲或者電影裏面用的上吧。github

1.1-2

Other than speed, what other measures of efficiency might one use in a real-world setting?算法

這個問題在公開課上有很好的討論。空間複雜度(內存和硬盤的佔用率),實現方便程度,安全性,容易維護性,等等,都是實際工程須要討論的。shell

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語言的特性來減小開銷所能作到的:數據結構

Linus:利用二級指針刪除單向鏈表app

Alan Cox:單向鏈表中prev指針的妙用

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.

這題是考察美國學生的小學數學計算能力麼?太沒技術含量啦……

因此我就不作了,嗯

能夠到另外一位老兄的習題集裏面去看

相關文章
相關標籤/搜索