Editing Naive algorithm

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
An algorithm is said to be '''naive''' when it is simple and straightforward but does not exhibit a desirable level of [[Analysis of algorithms|efficiency]] (usually in terms of time, but also possibly memory) despite finding a correct solution or it does not find an optimal solution to an [[optimization 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 simple [[simulation]] or on [[brute force]] generation of candidate solutions with little or no attempt at [[optimization]]. 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 appropriate [[data structure]]s.
+
An algorithm is said to be '''naive''' when it is simple and straightforward but does not exhibit a desirable level of [[Analysis of algorithms|efficiency]] (usually in terms of time, but also possibly memory) despite finding a correct solution or it does not find an optimal solution to an [[optimization 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 simple [[simulation]] or on [[brute force]] generation of candidate solutions with little or no attempt at optimization. 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 appropriate [[data structure]]s.
  
 
For example, the naive algorithm for [[string searching]] entails trying to match the needle at every possible position in the haystack, doing an <math>O(m)</math> check at each step (where <math>m</math> is the length of the needle), giving an <math>O(mn)</math> runtime (where <math>n</math> is the length of the haystack). The realization that the check can be performed more efficiently using a hash function leads to the [[Rabin–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 the [[Knuth–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 the [[suffix tree]] data structure which reduces string search to mere traversal. All of these algorithms are more efficient than the naive algorithm.
 
For example, the naive algorithm for [[string searching]] entails trying to match the needle at every possible position in the haystack, doing an <math>O(m)</math> check at each step (where <math>m</math> is the length of the needle), giving an <math>O(mn)</math> runtime (where <math>n</math> is the length of the haystack). The realization that the check can be performed more efficiently using a hash function leads to the [[Rabin–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 the [[Knuth–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 the [[suffix tree]] data structure which reduces string search to mere traversal. All of these algorithms are more efficient than the naive algorithm.
  
 
[[Category:Algorithms]]
 
[[Category:Algorithms]]

Please note that all contributions to PEGWiki are considered to be released under the Attribution 3.0 Unported (see PEGWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)