Dovetailing (computer Science)
   HOME

TheInfoList



OR:

Dovetailing, in
algorithm design In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing c ...
, is a technique that interweaves different computations, performing them essentially simultaneously. Algorithms that use dovetailing are sometimes referred to as dovetailers.


Examples

Consider a
tree In botany, a tree is a perennial plant with an elongated stem, or trunk, usually supporting branches and leaves. In some usages, the definition of a tree may be narrower, including only woody plants with secondary growth, plants that are ...
that potentially contains a
path A path is a route for physical travel – see Trail. Path or PATH may also refer to: Physical paths of different types * Bicycle path * Bridle path, used by people on horseback * Course (navigation), the intended path of a vehicle * Desire p ...
of infinite length (but each node has only finitely many children): if a depth-first search is performed in this environment, the search may move down an infinite path and never return, potentially leaving part of the tree unexplored. However, if a
breadth-first search Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next de ...
is used, the existence of an infinite path is no longer a problem: each
node In general, a node is a localized swelling (a "knot") or a point of intersection (a vertex). Node may refer to: In mathematics * Vertex (graph theory), a vertex in a mathematical graph *Vertex (geometry), a point where two or more curves, lines ...
is visited in a branching manner according to its distance from the root, so an infinite path will only impact the part of the search travelling down that path. We can regard this tree as analogous to a collection of programs; in this case, the depth-first approach corresponds to running one program at a time, moving to the next only when the current program has finished running. In the case where one of the programs runs for an infinite amount of time, this transition will never happen. The breadth-first approach of visiting each child on the same level of the tree is an instance of dovetailing, where a single step is performed for every program before moving to the next. Thus, progress is made in each program, regardless of the potential existence of a non-terminating program. Another example is simulating a
non-deterministic Turing machine In theoretical computer science, a nondeterministic Turing machine (NTM) is a theoretical model of computation whose governing rules specify more than one possible action when in some given situations. That is, an NTM's next state is ''not'' comp ...
''M'' by a deterministic one (e.g. by a
universal Turing machine In computer science, a universal Turing machine (UTM) is a Turing machine that can simulate an arbitrary Turing machine on arbitrary input. The universal machine essentially achieves this by reading both the description of the machine to be simu ...
). In such case, we need to use dovetailing in case one of the computation branches of ''M'' contains an infinite loop.


Infinitely many simultaneous computations

In the case of an infinite number of programs, all potentially infinitely long, neither the breadth-first nor depth-first would be sufficient to ensure progress on all programs. Instead, the following technique can be used: perform the first step of the first program; next, perform the second step of the first program and first step of the second program; next, perform the third step of the first program, second step of the second program and first step of the third program; and so on. This is thus also known as diagonalization (as used e.g. in Haskell's "universe" package or "Omega" monad).


Etymology

An analogy with the interweaving ends of a dovetail joint in
woodworking Woodworking is the skill of making items from wood, and includes cabinet making (cabinetry and furniture), wood carving, joinery, carpentry, and woodturning. History Along with stone, clay and animal parts, wood was one of the first mate ...
.


See also

* Recursive enumeration {{DEFAULTSORT:Dovetailing (Computer Science) Analysis of algorithms