Dovetailing (computer science)

Dovetailing, in algorithm design, is a technique that interweaves different computations, performing them essentially simultaneously. Algorithms that use dovetailing are sometimes referred to as dovetailers.

Consider a tree that potentially contains a path of infinite length: 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 is used, the existence of an infinite path is no longer a problem: each node 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 corresponds to 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 program of infinite runtime.

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 first step of the second program and the second step of the first program; next, perform the first step of the third program, the second step of the second program, and the third step of the first program; and so on.

Note: We could dovetail the depth-first (no dovetailing) and breadth-first (full dovetailing) mechanism of combining algorithms. This recursive application of the dovetailing algorithm to itself leads to an infinite number of new algorithms, each involving slightly less total dovetailing.

Etymology

  1. The term might have come from dovetail card shuffling.
  2. An analogy with the interweaving ends of a dovetail joint in woodworking.
gollark: It doesn't *do* anything. It just looks cool because of the syntax highlighting.
gollark: ```lualocal a="potato"local function b(c)return fs.combine(c,"")end;local function d(c)if b(c)==""then return{}end;local e,f={},c;repeat table.insert(e,1,fs.getName(f))f=fs.getDir(f)until f==""return e end;local function g(h,i,j)return{table.unpack(h,i,j)}end;local function k(l)local m=type(l)if m=="number"then return tostring(l)elseif m=="string"then return textutils.serialise(l)elseif m=="table"then local n="{"for o,p in pairs(l)do n=n..string.format("[%s]=%s,",k(o),k(p))end;return n.."}"elseif m=="boolean"then return tostring(l)else error("Unsupported type "..m)end end;local function q(m)local r=g(m)local s=#r;local p=r[s]r[s]=nil;return r,p end;local t=".crane-persistent/"..a;local function u(v,w)return string.sub(v,1,#w)==w end;local function x(v,w)return string.sub(v,-#w,-1)==w end;local function y(v,z)return string.find(v,z)~=nil end;local function A(B)return function(C)local D={}for E,F in pairs(B)do local l=C[F]if type(l)=="table"thenl=copy(l)end;D[F]=l end;return D end end;local function G(H,c)local I=H;local c=c;if type(c)=="string"then c=d(c)end;for E,J in pairs(c)do if type(I)~="table"then error("Path segment "..J.." is nonexistent or not a directory; full path "..k(c))end;I=I[J]end;return I end;local function K(H,c)local L,M=q(d(c))local N=G(H,L)or H;return N,M end;local function O(P)local m={}local function Q(R)table.insert(m,R)return""end;Q(P:gsub("(.-)\r?\n",Q))return m end;local function S(T,U)local O=O(T)local V={}local R=0;function V.close()end;if not U then function V.readLine()R=R+1;return O[R]end;function V.readAll()return T end else local W=T;function V.read()local X=string.byte(W:sub(1,1))W=W:sub(2)return X end end;return V end;local function Y(Z,U)local V={}function V.close()end;function V.flush()end;if not U then function V.write(m)return Z(m)end;function V.writeLine(m)return Z(m.."\n")end else function V.write(_)return Z(string.char(_))end end;return V end;local function a0(a1)local a2=a1.options;local H=a1.tree;local a3=A{"getName",```
gollark: Yep!
gollark: A fun idea is to either run what they want you to on Linux (and report faithfully the errors) or on a VM.
gollark: The quality is *horrible*.

See also

  • Recursive enumeration
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.