Jump to content

Naïve algorithm

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jochen Burghardt (talk | contribs) at 19:06, 18 November 2019 (suggest to use mergesort to avoid worst / avg. case discussion here; 'considerable' is WP:POV; use 'lb' to avoid discussion of 'up to constant factor' in O(.); phrase 'require...' consistent with worst case; bubble/merge-sort discussion says nothing about prototyping; I believe buggy algorithms aren't 'naive'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A naïve algorithm (or naive method) is typically a very simple solution to a problem, which represents the intuitive approach taken by one unfamiliar with the problem domain. It is meant to describe a suboptimal algorithm compared to a "clever" (but less simple) algorithm. Naïve algorithms usually consume larger amounts of resources (time, space, memory accesses, ...), but are simple to devise and implement.

An example of a naïve algorithm is bubble sort, which is only a few lines long and easy to understand, but has a O(n2) time complexity. A more "clever" algorithm is mergesort, which, although being more complicated than bubble sort, has a O(n lb(n)) complexity. For instance, sorting a list of 100 items with bubble sort may require up to 10,000 iterations, while sorting the same list with mergesort requires at most 700 iterations, making mergesort a much faster algorithm than bubble sort.

Naïve algorithms are mostly used for prototyping purposes; they are often not acceptable in production-level software products.

Another sense of the term implies an algorithm which may have certain bugs, or fail to account for corner cases; for instance, the naïve implementations of various operations on linked lists and binary trees either leak memory or corrupt data based on incorrect pointer arithmetic.[dubiousdiscuss]