什么是Naive algorithm

来源:互联网 发布:软件行业ppt 编辑:程序博客网 时间:2024/05/17 07:09


Naive algorithm

这篇文章是转载来的,这个应该是翻译成朴素算法吧。翻译成简单算法感觉不是很高大上。。读者觉得不对的,请指出。。

源地址:http://wcipeg.com/wiki/Naive_algorithm#

From PEGWiki

An algorithm is said to be naive when it is simple and straightforward but does not exhibit a desirable level ofefficiency (usually in terms of time, but also possibly memory) despite finding a correct solution or it does not find an optimal solution to anoptimization problem, and better algorithms can be designed and implemented with more careful thought and clever techniques. Naive algorithms are easy to discover, often easy to prove correct, and often immediately obvious to the problem solver. They are often based on simplesimulation or onbrute force generation of candidate solutions with little or no attempt atoptimization. Despite their inefficiency, naive algorithms are often the stepping stone to more efficient, perhaps even asymptotically optimal algorithms, especially when their efficiency can be improved by choosing more appropriatedata structures.

For example, the naive algorithm for string searching entails trying to match the needle at every possible position in the haystack, doing anO(m) check at each step (where m is the length of the needle), giving anO(mn) runtime (wheren is the length of the haystack). The realization that the check can be performed more efficiently using a hash function leads to theRabin–Karp algorithm. The realization that preprocessing the needle can allow a failed attempt at matching to be used to rule out other possible positions leads to theKnuth–Morris–Pratt algorithm. The realization that preprocessing the haystack can allow needles to be "looked up" in the haystack rather than searched for in a linear fashion leads to thesuffix tree data structure which reduces string search to mere traversal. All of these algorithms are more efficient than the naive algorithm.


0 0
原创粉丝点击