《Algorithms in Java: Parts 1-4, Third Edition》是一本用Java語言講解算法的書,我正在閱讀中。因為是英文原版的,復習的時候不容易看。因為中國人嘛,對母語的反應是最快的。雖然英語不是很好,以前也沒翻譯過什么東西,但是還是想盡我所能,以意譯為主吧,學好算法這門必修課,和大家共同分享。
2007年10月11日 21:00:01
2007年10月12日 8:35:34 翻譯
Form:《Algorithms in Java: Parts 1-4, Third Edition》
1、
Most algorithms of interest involve methods of organizing the data
involved in the computation. Objects created in this way are called
data structures, and they also are central objects of study in computer
science. Thus, algorithms and data structures go hand in hand.
大多數重要的算法,包含了在計算中方法需要處理的組織起來的數據。以這種方式創建的對象我們稱之為數據結構。它們也是計算機科學研究和核心問題。因此,數據結構和算法是密不可分的。
(特定的數據結構有特定的算法,比如:估算降雨量要用毫米數,不能用雨滴的個數。在這種問題上,越是精確,越是沒意義。模糊數學里的東西。)
2、
Careful algorithm design is an extremely effective part of the process
of solving a huge problem, whatever the applications area.
無論在什么應用領域,精心設計的算法能夠非常高效地解決大的問題。
(好像聽人說過,一種科學,如果沒用上數學,那就稱不上是嚴謹的科學。大概這個意思吧。)
3、
When a huge or complex computer program is to be developed, a great
deal of effort must go into understanding and defining the problem to
be solved, managing its complexity, and decomposing it into smaller
subtasks that can be implemented easily.
當要開發一個復雜的計算機程序,必須付出巨大的努力理解和定義問題的解決方式,管理復雜度,把它分解成可以很容易實現的子任務。
(分而治之是最基本的思想)
4、
The Java libraries contain implementations of a host of fundamental
algorithms. However, implementing simple versions of basic algorithms
helps us to understand them better and thus to more effectively use and
tune advanced versions from a library. More important, the opportunity
to reimplement basic algorithms arises frequently. The primary reason
to do so is that we are faced, all too often, with completely new
computing environments (hardware and software) with new features that
old implementations may not use to best advantage. In other words, we
often implement basic algorithms tailored to our problem, rather than
depending on a system routine, to make our solutions more portable and
longer lasting. Another common reason to reimplement basic algorithms
is that, despite the advances embodied in Java, the mechanisms that we
use for sharing software are not always sufficiently powerful to allow
us to conveniently tailor library programs to perform effectively on
specific tasks.
java庫包含了大量的基礎算法的實現。然而,實現簡單版本的基本算法幫助我們更好地理解它們,這樣就能更高效地
運用它們,并且從庫中使用更高級的版本。更重要的是,重新實現基本算法的機會變得很頻繁。這樣做的主要原因是我們會遇到,并且經常遇到全新的計算機環境
(軟件和硬件),這樣舊有的實現就可能不是最佳的了。換句話說,我們經常根據我們的問題實現基本算法,而不是例行公事地,讓我們的解決方案更便捷、持續得
更長久。另一個很普遍的原因是重新實現基本的算法,不管java包含的算法如何優秀,我們在設計軟件時采用它實現的機制,并不能總是滿足我們特定任務的需
要。
(也就是說在特定的情況下,需要我們根據問題來實現基本的算法,而不是java的庫,庫只是通用的,有時并不能滿足特定的需要。不要以為學習基本算法是在重新發明輪子。有個叫劉喆的同學也說過類似的話^_^)
5、
Computer programs are often overoptimized. It may not be worthwhile to
take pains to ensure that an implementation of a particular algorithm
is the most efficient possible unless the algorithm is to be used for
an enormous task or is to be used many times.
計算機程序經常地被過度地優化。有時,努力地確保一個算法的實現是最高效的并不值得,除非那個算法被用來處理復雜的任務,或者會被多次地使用。
(在
Joshua
Bloch著的《Effective
Java》中有過相同的論述,很有意思。他提出兩條規則:第一條,不要做優化。第二條,(僅針對專家)還是不要做優化---也就是說,在你沒有絕對清晰的
未優化方案之前,請不要做優化。他是java庫的設計者之一,說話的分量夠重吧。現在好像跳到google了。)
6、
We do pay careful attention to carefully coding the critical parts of
the algorithms, and take pains to note where low-level optimization
effort could be most beneficial.
我們一定要特別注意仔細地為算法關鍵部分的編碼,努力地注意以很小代價做的優化,獲得最好的效果。
(也就是算法中最核心的部分,有點80/20原則的意味。)
7、
The choice of the best algorithm for a particular task can be a
complicated process, perhaps involving sophisticated mathematical
analysis. The branch of computer science that comprises the study of
such questions is called analysis of algorithms.
為一個特定的任務選擇最佳算法可能是一個復雜的過程,也許包含了精密的數學分析。算法分析就是研究這種問題的學科,它是計算機科學的一個分支。
(看來學計算機要學的深入,不學數學是不行的,我得惡補一下了。)
8、
We should not use an algorithm without having an idea of what resources
it might consume, and we strive to be aware of how our algorithms might
be expected to perform.
我們不應該只是使用一個算法,而不在意他消耗了多少資源(時間和空間),我們應該密切留意我們的算法能否達到預期的效果。
(生了孩子就要對他/她負責,否則就不要生他/她。)