HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulefgl-5.8.2.0Haskell98

Data.Graph.Inductive.Query.DFS

Depth-first search algorithms.

Names consist of:

  1. An optional direction parameter, specifying which nodes to visit next.

u

undirectional: ignore edge direction

r

reversed: walk edges in reverse

x

user defined: speciy which paths to follow

  1. "df" for depth-first

  2. A structure parameter, specifying the type of the result.

    s

    Flat list of results

    f

    Structured

    Tree

    of results

  3. An optional "With", which instead of putting the found nodes directly into the result, adds the result of a computation on them into it.

  4. An optional prime character, in which case all nodes of the graph will be visited, instead of a user-given subset.

  • 1 type
  • 31 values
  • Packagefgl-5.8.2.0
  • Exports32
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceDFS.hs

Standard

11 declarations
valuexdfsWith
  1. :: Graph gr
  2. => CFun a b [Node]

    Mapping from a node to its neighbours to be visited as well. suc' for example makes xdfsWith traverse the graph following the edge directions, while pre' means reversed directions.

  3. -> CFun a b c

    Mapping from the Context of a node to a result value.

  4. -> [Node]

    Nodes to be visited.

  5. -> gr a b
  6. -> [c]
#

Most general DFS algorithm to create a list of results. The other list-returning functions such as dfs are all defined in terms of this one.

xdfsWith d f vs = preorderF . xdffWith d f vs
valuexdfWith
  1. :: Graph gr
  2. => CFun a b [Node]
  3. -> CFun a b c
  4. -> [Node]
  5. -> gr a b
  6. -> ([Tree c], gr a b)
#

Most general DFS algorithm to create a forest of results, otherwise very similar to xdfsWith. The other forest-returning functions such as dff are all defined in terms of this one.

Undirected

6 declarations
valueudfs :: Graph gr => [Node] -> gr a b -> [Node]
#

Undirected depth-first search, obtained by following edges regardless of their direction.

valueudff :: Graph gr => [Node] -> gr a b -> [Tree Node]
#

Undirected depth-first forest, obtained by following edges regardless of their direction.

Reversed

6 declarations
valuerdff :: Graph gr => [Node] -> gr a b -> [Tree Node]
#

Reverse depth-first forest, obtained by following predecessors.

valuerdfs :: Graph gr => [Node] -> gr a b -> [Node]
#

Reverse depth-first search, obtained by following predecessors.

Applications of depth first search/forest

4 declarations
valuescc :: Graph gr => gr a b -> [[Node]]
#

Collection of strongly connected components

Applications of undirected depth first search/forest

4 declarations
valuecondensation :: Graph gr => gr a b -> gr [Node] ()
#

The condensation of the given graph, i.e., the graph of its strongly connected components.