Output-sensitive Algorithm
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, an output-sensitive algorithm is an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
whose running time depends on the size of the output, instead of, or in addition to, the size of the input. For certain problems where the output size varies widely, for example from linear in the size of the input to quadratic in the size of the input, analyses that take the output size explicitly into account can produce better runtime bounds that differentiate algorithms that would otherwise have identical asymptotic complexity.


Examples


Division by subtraction

A simple example of an output-sensitive algorithm is given by the
division algorithm A division algorithm is an algorithm which, given two integers N and D, computes their quotient and/or remainder, the result of Euclidean division. Some are applied by hand, while others are employed by digital circuit designs and software. Divis ...
''division by subtraction'' which computes the quotient and remainder of dividing two positive integers using only addition, subtraction, and comparisons: def divide(number: int, divisor: int) -> Tuple nt, int """Division by subtraction.""" if not divisor: raise ZeroDivisionError if number < 1 or divisor < 1: raise ValueError( f"Positive integers only for " f"dividend () and divisor ()." ) q = 0 r = number while r >= divisor: q += 1 r -= divisor return q, r Example output: >>> divide(10, 2) (5, 0) >>> divide(10, 3) (3, 1) This algorithm takes Θ(Q) time, and so can be fast in scenarios where the quotient Q is known to be small. In cases where Q is large however, it is outperformed by more complex algorithms such as
long division In arithmetic, long division is a standard division algorithm suitable for dividing multi-digit Hindu-Arabic numerals (Positional notation) that is simple enough to perform by hand. It breaks down a division problem into a series of easier steps. ...
.


Computational geometry

Convex hull algorithms Algorithms that construct convex hulls of various objects have a broad range of applications in mathematics and computer science. In computational geometry, numerous algorithms are proposed for computing the convex hull of a finite set of points ...
for finding the
convex hull In geometry, the convex hull or convex envelope or convex closure of a shape is the smallest convex set that contains it. The convex hull may be defined either as the intersection of all convex sets containing a given subset of a Euclidean space ...
of a finite set of points in the plane require Ω(''n'' log ''n'') time for ''n'' points; even relatively simple algorithms like the
Graham scan Graham's scan is a method of finding the convex hull of a finite set of points in the plane with time complexity O(''n'' log ''n''). It is named after Ronald Graham, who published the original algorithm in 1972. The algorithm finds all vertices o ...
achieve this lower bound. If the convex hull uses all ''n'' points, this is the best we can do; however, for many practical sets of points, and in particular for random sets of points, the number of points ''h'' in the convex hull is typically much smaller than ''n''. Consequently, output-sensitive algorithms such as the
ultimate convex hull algorithm Ultimate or Ultimates may refer to: Arts, entertainment, and media Music Albums * ''Ultimate'' (Jolin Tsai album) * ''Ultimate'' (Pet Shop Boys album) *''Ultimate!'', an album by The Yardbirds *'' The Ultimate (Bryan Adams Album)'', a compilati ...
and
Chan's algorithm In computational geometry, Chan's algorithm, named after Timothy M. Chan, is an optimal output-sensitive algorithm to compute the convex hull of a set P of n points, in 2- or 3-dimensional space. The algorithm takes O(n \log h) time, where h is t ...
which require only O(''n'' log ''h'') time are considerably faster for such point sets. Output-sensitive algorithms arise frequently in
computational geometry Computational geometry is a branch of computer science devoted to the study of algorithms which can be stated in terms of geometry. Some purely geometrical problems arise out of the study of computational geometric algorithms, and such problems ar ...
applications and have been described for problems such as
hidden surface removal In 3D computer graphics, hidden-surface determination (also known as shown-surface determination, hidden-surface removal (HSR), occlusion culling (OC) or visible-surface determination (VSD)) is the process of identifying what surfaces and parts o ...
and resolving
range filter Range may refer to: Geography * Range (geographic), a chain of hills or mountains; a somewhat linear, complex mountainous or hilly area (cordillera, sierra) ** Mountain range, a group of mountains bordered by lowlands * Range, a term used to i ...
conflicts in router tables. Frank Nielsen describes a general paradigm of output-sensitive algorithms known as ''grouping and querying'' and gives such an algorithm for computing cells of a
Voronoi diagram In mathematics, a Voronoi diagram is a partition of a plane into regions close to each of a given set of objects. In the simplest case, these objects are just finitely many points in the plane (called seeds, sites, or generators). For each seed th ...
.Frank Nielsen. Grouping and Querying: A Paradigm to Get Output-Sensitive Algorithms. Revised Papers from the Japanese Conference on Discrete and Computational Geometry, pp.250–257. 1998. {{ISBN, 3-540-67181-1. http://www.sonycsl.co.jp/person/nielsen/PT/groupingquerying/n-grouping.ps Nielsen breaks these algorithms into two stages: estimating the output size, and then building data structures based on that estimate which are queried to construct the final solution.


Generalizations

A more general kind of output-sensitive algorithms are
enumeration algorithm In computer science, an enumeration algorithm is an algorithm that enumerates the answers to a computational problem. Formally, such an algorithm applies to problems that take an input and produce a list of solutions, similarly to function problem ...
s, which enumerate the set of solutions to a problem. In this context, the performance of algorithms is also measured in an output-sensitive way, in addition to more sensitive measures, e.g., bounded the delay between any two successive solutions.


See also

*
Lazy evaluation In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations (sharing). The b ...


References

Analysis of algorithms Articles with example Python (programming language) code