<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.algo.informatik.tu-darmstadt.de/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Flomm</id>
	<title>Algowiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.algo.informatik.tu-darmstadt.de/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Flomm"/>
	<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/Special:Contributions/Flomm"/>
	<updated>2026-10-27T13:25:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Category:Minimal_Spanning_Tree&amp;diff=1800</id>
		<title>Category:Minimal Spanning Tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Category:Minimal_Spanning_Tree&amp;diff=1800"/>
		<updated>2014-11-07T15:49:38Z</updated>

		<summary type="html">&lt;p&gt;Flomm: /* Output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[[File:min_span_tree.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
The red colored edges are the minimal spanning tree of this graph.&lt;br /&gt;
&lt;br /&gt;
== Input ==&lt;br /&gt;
&lt;br /&gt;
* A undirected connected graph &amp;lt;math&amp;gt;G=(V,E)&amp;lt;/math&amp;gt;&lt;br /&gt;
* A weight &amp;lt;math&amp;gt;w(u,v)&amp;lt;/math&amp;gt; for each edge &amp;lt;math&amp;gt;(u,v) \in E&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Output ==&lt;br /&gt;
&lt;br /&gt;
A acylic subset &amp;lt;math&amp;gt;T \subseteq E&amp;lt;/math&amp;gt; in which &amp;lt;math&amp;gt;w(T) = \sum_{(u,v) \in T} w(u,v)&amp;lt;/math&amp;gt; is minimal.&lt;br /&gt;
&lt;br /&gt;
== Generic algorihm ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 Generic-MST(G, w)&lt;br /&gt;
 1 &#039;&#039;A&#039;&#039; &amp;amp;larr; &amp;amp;empty;&lt;br /&gt;
 2 &#039;&#039;&#039;while&#039;&#039;&#039; &#039;&#039;A&#039;&#039; is not a spanning tree&lt;br /&gt;
 3     &#039;&#039;&#039;do&#039;&#039;&#039; determine a edge &#039;&#039;(u,v)&#039;&#039;&lt;br /&gt;
 4              &#039;&#039;A&#039;&#039; &amp;amp;larr; &#039;&#039;A&#039;&#039; &amp;amp;cup; &#039;&#039;{(u,v)}&#039;&#039;&lt;br /&gt;
 5 &#039;&#039;&#039;return&#039;&#039;&#039; &#039;&#039;A&#039;&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Known algorithms ==&lt;br /&gt;
&lt;br /&gt;
* [[Kruskal]]&lt;br /&gt;
* [[Prim]]&lt;/div&gt;</summary>
		<author><name>Flomm</name></author>
	</entry>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Category:Minimal_Spanning_Tree&amp;diff=1799</id>
		<title>Category:Minimal Spanning Tree</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Category:Minimal_Spanning_Tree&amp;diff=1799"/>
		<updated>2014-11-07T15:47:44Z</updated>

		<summary type="html">&lt;p&gt;Flomm: Created page with &amp;quot;== Introduction ==  400px  The red colored edges are the minimal spanning tree of this graph.  == Input ==  * A undirected connected graph &amp;lt;math&amp;gt;G=(...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[[File:min_span_tree.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
The red colored edges are the minimal spanning tree of this graph.&lt;br /&gt;
&lt;br /&gt;
== Input ==&lt;br /&gt;
&lt;br /&gt;
* A undirected connected graph &amp;lt;math&amp;gt;G=(V,E)&amp;lt;/math&amp;gt;&lt;br /&gt;
* A weight &amp;lt;math&amp;gt;w(u,v)&amp;lt;/math&amp;gt; for each edge &amp;lt;math&amp;gt;(u,v) \in E&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Output ==&lt;br /&gt;
&lt;br /&gt;
A acylic subset &amp;lt;math&amp;gt;T \subset E&amp;lt;/math&amp;gt; in which &amp;lt;math&amp;gt;w(T) = \sum_{(u,v) \in T} w(u,v)&amp;lt;/math&amp;gt; is minimal.&lt;br /&gt;
&lt;br /&gt;
== Generic algorihm ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 Generic-MST(G, w)&lt;br /&gt;
 1 &#039;&#039;A&#039;&#039; &amp;amp;larr; &amp;amp;empty;&lt;br /&gt;
 2 &#039;&#039;&#039;while&#039;&#039;&#039; &#039;&#039;A&#039;&#039; is not a spanning tree&lt;br /&gt;
 3     &#039;&#039;&#039;do&#039;&#039;&#039; determine a edge &#039;&#039;(u,v)&#039;&#039;&lt;br /&gt;
 4              &#039;&#039;A&#039;&#039; &amp;amp;larr; &#039;&#039;A&#039;&#039; &amp;amp;cup; &#039;&#039;{(u,v)}&#039;&#039;&lt;br /&gt;
 5 &#039;&#039;&#039;return&#039;&#039;&#039; &#039;&#039;A&#039;&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Known algorithms ==&lt;br /&gt;
&lt;br /&gt;
* [[Kruskal]]&lt;br /&gt;
* [[Prim]]&lt;/div&gt;</summary>
		<author><name>Flomm</name></author>
	</entry>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=File:Min_span_tree.jpg&amp;diff=1798</id>
		<title>File:Min span tree.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=File:Min_span_tree.jpg&amp;diff=1798"/>
		<updated>2014-11-07T15:36:04Z</updated>

		<summary type="html">&lt;p&gt;Flomm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Flomm</name></author>
	</entry>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Strongly_connected_components&amp;diff=1766</id>
		<title>Strongly connected components</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Strongly_connected_components&amp;diff=1766"/>
		<updated>2014-11-04T15:23:01Z</updated>

		<summary type="html">&lt;p&gt;Flomm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Input ==&lt;br /&gt;
&lt;br /&gt;
A [[Basic graph definitions|directed graph]] &amp;lt;math&amp;gt;G=(V,A)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Output ==&lt;br /&gt;
&lt;br /&gt;
A set of sets of nodes. Each set of nodes contains exactly the nodes of one [[Basic graph definitions#Connectedness|SCC]]. The correspondence between the [[Basic graph definitions#Connectedness|SCC]] and these sets of nodes is one-to-one.&lt;br /&gt;
&lt;br /&gt;
== Known algorithms ==&lt;br /&gt;
&lt;br /&gt;
# [[Kosaraju]]&lt;/div&gt;</summary>
		<author><name>Flomm</name></author>
	</entry>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Depth-first_search&amp;diff=1655</id>
		<title>Depth-first search</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Depth-first_search&amp;diff=1655"/>
		<updated>2014-10-30T14:13:28Z</updated>

		<summary type="html">&lt;p&gt;Flomm: Added stack implementation pseudocode&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Algorithms]]&lt;br /&gt;
[[Category:Search Algorithms]]&lt;br /&gt;
[[Category:Tree Algorithms]]&lt;br /&gt;
[[Category:Graph Traversal]]&lt;br /&gt;
&lt;br /&gt;
== General information ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithmic problem:&#039;&#039;&#039; [[Graph traversal]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Type of algorithm:&#039;&#039;&#039; loop&lt;br /&gt;
&lt;br /&gt;
== Abstract view ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
# For each node, an arbitrary but fixed ordering of the outgoing arcs is assumed. An arc &amp;lt;math&amp;gt;(v,w)&amp;lt;/math&amp;gt; preceding an arc &amp;lt;math&amp;gt;(v,w&#039;)&amp;lt;/math&amp;gt; in this ordering is called &#039;&#039;&#039;lexicographically smaller&#039;&#039;&#039; than &amp;lt;math&amp;gt;(v,w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Let &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;p&#039;&amp;lt;/math&amp;gt; be two paths that start from the same node &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, but may or may not have the same endnode. Let &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; be the last common node such that the subpaths of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;p&#039;&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; up to &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; are identical (possibly &amp;lt;math&amp;gt;v=w&amp;lt;/math&amp;gt;). If the next arc of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is lexicographically smaller than the next arc of &amp;lt;math&amp;gt;p&#039;&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is said to be &#039;&#039;&#039;lexicograpically smaller&#039;&#039;&#039; than &amp;lt;math&amp;gt;p&#039;&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Note that the lexicographically smallest path from &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;w\in V&amp;lt;/math&amp;gt; is well defined and unique. With respect to a starting node &amp;lt;math&amp;gt;s\in V&amp;lt;/math&amp;gt;, a node &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt; is &#039;&#039;&#039;lexicographically smaller&#039;&#039;&#039; than &amp;lt;math&amp;gt;w\in V&amp;lt;/math&amp;gt; if the lexicographically smallest path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is lexicographically smaller than the lexicographically smallest path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;.&lt;br /&gt;
# In all of the above cases, the reverse relation is called &#039;&#039;&#039;lexicographically larger&#039;&#039;&#039;.&lt;br /&gt;
# A node &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt; is &#039;&#039;&#039;lexicographically smaller&#039;&#039;&#039; (resp., &#039;&#039;&#039;lexicograpically larger&#039;&#039;&#039;) than a path &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; if the lexicographically smallest path from the start node of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is lexicographically smaller (resp., larger) than &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;. (Note the asymmetry: In both cases, the lexicographically &#039;&#039;smallest&#039;&#039; path to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is used.)&lt;br /&gt;
# In all cases, we also say &#039;&#039;&#039;precedes&#039;&#039;&#039; and &#039;&#039;&#039;succeeds&#039;&#039;&#039;, respectively, instead of &amp;quot;is lexicograpically smaller/larger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Additional output:&#039;&#039;&#039;&lt;br /&gt;
# Each node has two Boolean labels with semantics, &amp;quot;is seen&amp;quot; and &amp;quot;is finished&amp;quot;.&lt;br /&gt;
# An arborescence &amp;lt;math&amp;gt;A=(V&#039;,A&#039;)&amp;lt;/math&amp;gt; rooted at &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;V&#039;\subseteq V&amp;lt;/math&amp;gt; is the set of all nodes reachable from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (including &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;). For each node &amp;lt;math&amp;gt;v\in V&#039;&amp;lt;/math&amp;gt;, the path in &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is the lexicographically smallest &amp;lt;math&amp;gt;(s,v)&amp;lt;/math&amp;gt;-path in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Specific characteristic:&#039;&#039;&#039;&lt;br /&gt;
The nodes may be returned either in lexicographic order or (alternatively or simultaneously) in an order that fulfills the following property:&lt;br /&gt;
Let &amp;lt;math&amp;gt;v,w\in V&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is seen before &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. If there is a path from &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is finished prior to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Auxiliary data:&#039;&#039;&#039;&lt;br /&gt;
# A stack &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; whose elements are nodes in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Each node  has a &#039;&#039;&#039;current arc&#039;&#039;&#039; &amp;lt;math&amp;gt;a_v\in V&amp;lt;/math&amp;gt;, which is either void or an outgoing arc &amp;lt;math&amp;gt;a_v=(v,w)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Invariant:&#039;&#039;&#039; &lt;br /&gt;
Before and after each iteration:&lt;br /&gt;
# &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; forms a path &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; from the start node &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to some other node, that is, the order of the nodes on &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the order in which they appear in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; (start node &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; at the bottom of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;).&lt;br /&gt;
# For each node not yet seen, the current arc is the first arc (or void if the node has no outgoing arcs).&lt;br /&gt;
# For each node &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;:&lt;br /&gt;
## If there are arcs &amp;lt;math&amp;gt;(v,w)\in A&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is not yet seen, the current arc equals or precedes the first such arc.&lt;br /&gt;
## The subpath of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; from the start node &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the lexicographically first &amp;lt;math&amp;gt;(s,v)&amp;lt;/math&amp;gt;-path.&lt;br /&gt;
# The nodes on &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; are seen but not finished. Let &amp;lt;math&amp;gt;p+a&amp;lt;/math&amp;gt; denote the concatenation of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; with the current arc &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; of the last node of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;. The nodes that are lexicographically smaller than &amp;lt;math&amp;gt;p+a&amp;lt;/math&amp;gt; are seen and finished, and the nodes that lexicographically succeed &amp;lt;math&amp;gt;p+a&amp;lt;/math&amp;gt; are neither seen nor finished. (Note that nothing is said about the head of &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Variant:&#039;&#039;&#039; Either one node is finished or the current arc of one node is moved forward.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Break condition:&#039;&#039;&#039; &amp;lt;math&amp;gt;S=\emptyset&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Induction basis ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Abstract view:&#039;&#039;&#039; No node is finished. The start node &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; is seen, no other node is seen. The start node is the only element of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. The current arc of each node is its first outgoing arc. If the nodes are to be returned in lexicographic order, the start node &amp;lt;math&amp;gt;&amp;lt;/math&amp;gt; is, initially, the only member of the output sequence; otherwise, the initial output sequence is empty. Arborescence &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is initialized so as to contain &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and nothing else.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Implementation:&#039;&#039;&#039; Obvious.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Proof:&#039;&#039;&#039; Obvious.&lt;br /&gt;
&lt;br /&gt;
== Induction step ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Abstract view:&#039;&#039;&#039;&lt;br /&gt;
# Let &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; be the last node of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; (=the top element of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;).&lt;br /&gt;
# While the current arc of &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is not void and while the head of the current arc is labeled as seen: Move the current arc one step forward.&lt;br /&gt;
# If the current arc of &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is not void, say, &amp;lt;math&amp;gt;a_v=(v,w)&amp;lt;/math&amp;gt;:&lt;br /&gt;
## Insert &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;(v,w)&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;.&lt;br /&gt;
## Push &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
## Label &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; as seen.&lt;br /&gt;
## If the output order is the lexicographic one: Append &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; to the output sequence.&lt;br /&gt;
# Otherwise:&lt;br /&gt;
## Remove &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;&lt;br /&gt;
## Label &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; as finished.&lt;br /&gt;
## If the output order is &#039;&#039;&#039;not&#039;&#039;&#039; the lexicographic one: Put &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; in the output sequence.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Implementation:&#039;&#039;&#039; Obvious.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Proof:&#039;&#039;&#039;&lt;br /&gt;
The loop &#039;&#039;variant&#039;&#039; is obviously fulfilled.&lt;br /&gt;
&lt;br /&gt;
The first point of the &#039;&#039;invariant&#039;&#039; is obviously fulfilled, too. The second point follows from the fact that the current arc of a node is initialized to be the node&#039;s very first outgoing arc and only changed after the node is labeled as &#039;&#039;seen&#039;&#039;. Point 3.1 follows from the fact that the current arc never skips an arc that points to an unseen node.&lt;br /&gt;
&lt;br /&gt;
For point 3.2, let &amp;lt;math&amp;gt;w\neq v&amp;lt;/math&amp;gt; be the last node on &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;p&#039;&amp;lt;/math&amp;gt; such that both paths are identical from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; (possibly, &amp;lt;math&amp;gt;w=s&amp;lt;/math&amp;gt;). Further, let &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; be the immediate successors of &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;p&#039;&amp;lt;/math&amp;gt;, respectively. Then &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; has been seen before &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;. Note that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; has not been seen earlier than &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; (in fact, later, unless &amp;lt;math&amp;gt;v=u&amp;lt;/math&amp;gt;). In summary, &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; has been seen before &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Since there is a path from &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, the correctness proof [[#Correctness|below]] will prove point 3.2.&lt;br /&gt;
&lt;br /&gt;
When a node is pushed on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, it is neither seen nor finished immediately before that iteration and then labeled as seen in that iteration. The node is finished when it leaves &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Both facts together give the first sentence of point 4. The other statements of point 4 follow from the observation that the concatenation of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; with the current arc of the endnode of &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; increases lexicographically in each iteration.&lt;br /&gt;
&lt;br /&gt;
== Correctness ==&lt;br /&gt;
&lt;br /&gt;
It is easy to see that each operation of the algorithm is well defined. Due to the variant, the loop terminates after a finite number of steps. Immediately before the last iteration, &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; consists of the start node &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; only, and the current arc of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; is void. Therefore, &#039;&#039;all&#039;&#039; nodes reachable from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; except for &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; itself are lexicographically smaller than &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; at that moment. Due to point 4 of the invariant, all of these nodes are finished. In the last iteration, &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; is finished as well.&lt;br /&gt;
&lt;br /&gt;
So, it remains to show that the specific characteristic is fulfilled in both cases.&lt;br /&gt;
Due to point 3.2 of the invariant, a node is seen for the first time via its lexicographically smallest path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;. Since the current path increases lexicographically in each iteration, the nodes are labeled as seen in lexicographic order. So consider the second, the non-lexicographic case.&lt;br /&gt;
Let &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; be seen before &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; and assume there is a path from &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. We have to show that &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is finished prior to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;p&#039;&amp;lt;/math&amp;gt; denote the lexicographically smallest &amp;lt;math&amp;gt;(v,w)&amp;lt;/math&amp;gt;-path. There is a stage in which this path is a subpath of the current path &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;. Clearly, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; cannot be removed from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; before &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. This proves the claim.&lt;br /&gt;
&lt;br /&gt;
== Complexity ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Statement:&#039;&#039;&#039; The asymptotic complexity is in &amp;lt;math&amp;gt;\Theta(|V|+|A|)&amp;lt;/math&amp;gt; in the worst case.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Proof:&#039;&#039;&#039;&lt;br /&gt;
For every node reachable from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (including &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;), the algorithm processes each of its outgoing arcs exactly one. And from each of these nodes, the algorithm goes backwards exactly once. Obviously, each of these steps requires a constant number of operations.&lt;br /&gt;
&lt;br /&gt;
== Remark ==&lt;br /&gt;
&lt;br /&gt;
Alternatively, DFS could be implemented as a recursive procedure. However, this excludes the option to implement DFS as an iterator, which means to turn the loop inside-out (cf. remarks on [[Graph traversal|graph traversal]]).&lt;br /&gt;
&lt;br /&gt;
== Pseudocode recursive implementation == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== DFS(&#039;&#039;G&#039;&#039;) ====&lt;br /&gt;
:&#039;&#039;&#039;for&#039;&#039;&#039; each vertex &#039;&#039;u&#039;&#039; &amp;amp;isin; &#039;&#039;V&#039;&#039; [&#039;&#039;G&#039;&#039;] &lt;br /&gt;
::&#039;&#039;&#039;do&#039;&#039;&#039; color[&#039;&#039;u&#039;&#039;] &amp;amp;larr; WHITE&lt;br /&gt;
::: &#039;&#039;&amp;amp;pi;&#039;&#039;[&#039;&#039;u&#039;&#039;] &amp;amp;larr; NIL&lt;br /&gt;
:&#039;&#039;time&#039;&#039; &amp;amp;larr; 0&lt;br /&gt;
:: &#039;&#039;&#039;do if&#039;&#039;&#039; &#039;&#039;color&#039;&#039;[&#039;&#039;u&#039;&#039;] == WHITE&lt;br /&gt;
::: &#039;&#039;&#039;then&#039;&#039;&#039; DFS-VISiT(&#039;&#039;u&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====DFS-VISIT(&#039;&#039;u&#039;&#039;)====&lt;br /&gt;
: &#039;&#039;color&#039;&#039;[&#039;&#039;u&#039;&#039;] &amp;amp;larr; GRAY   &lt;br /&gt;
: &#039;&#039;time&#039;&#039; &amp;amp;larr; &#039;&#039;time&#039;&#039; + 1&lt;br /&gt;
: &#039;&#039;d&#039;&#039;[&#039;&#039;u&#039;&#039;] &amp;amp;larr; &#039;&#039;time&#039;&#039;&lt;br /&gt;
: &#039;&#039;&#039;for&#039;&#039;&#039; each &#039;&#039;v&#039;&#039; &amp;amp;isin; &#039;&#039;Adj&#039;&#039;[&#039;&#039;u&#039;&#039;]&lt;br /&gt;
:: &#039;&#039;&#039;do if&#039;&#039;&#039; &#039;&#039;color&#039;&#039;[&#039;&#039;v&#039;&#039;] = WHITE&lt;br /&gt;
::: &#039;&#039;&#039; then &#039;&#039;&#039; &amp;amp;pi; [&#039;&#039;v&#039;&#039;] &amp;amp;larr; &#039;&#039;u&#039;&#039;&lt;br /&gt;
:::: DFS-VISIT(&#039;&#039;v&#039;&#039;)&lt;br /&gt;
:&#039;&#039;color&#039;&#039;[&#039;&#039;u&#039;&#039;] &amp;amp;larr; BLACK&lt;br /&gt;
:&#039;&#039;f&#039;&#039;[&#039;&#039;u&#039;&#039;] &amp;amp;larr; &#039;&#039;time&#039;&#039; &amp;amp;larr; &#039;&#039;time&#039;&#039; + 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pseudocode stack implementation ==&lt;br /&gt;
&lt;br /&gt;
====DFS(&#039;&#039;s&#039;&#039;)====&lt;br /&gt;
: &#039;&#039;S = new Stack()&#039;&#039;&lt;br /&gt;
: &#039;&#039;s.IsSeen = true&#039;&#039;&lt;br /&gt;
: &#039;&#039;S.push(s)&#039;&#039;&lt;br /&gt;
: &#039;&#039;&#039;while&#039;&#039;&#039; &#039;&#039;S&#039;&#039; &amp;amp;ne; &amp;amp;empty;&lt;br /&gt;
:: &#039;&#039;n&#039;&#039; = &#039;&#039;S.peek()&#039;&#039;&lt;br /&gt;
:: &#039;&#039;a&#039;&#039; = &#039;&#039;(v, w)&#039;&#039; = &#039;&#039;n.nextArc()&#039;&#039;&lt;br /&gt;
:: &#039;&#039;&#039;if&#039;&#039;&#039; &#039;&#039;a&#039;&#039; == &#039;&#039;null&#039;&#039;&lt;br /&gt;
::: &#039;&#039;n.IsFinised&#039;&#039; = &#039;&#039;true&#039;&#039;&lt;br /&gt;
::: &#039;&#039;S.pop()&#039;&#039;&lt;br /&gt;
:: &#039;&#039;&#039;else if&#039;&#039;&#039; &#039;&#039;w.IsSeen&#039;&#039; == &#039;&#039;false&#039;&#039;&lt;br /&gt;
::: &#039;&#039;w.IsSeen&#039;&#039; = &#039;&#039;true&#039;&#039;&lt;br /&gt;
::: &#039;&#039;S.push(w)&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Flomm</name></author>
	</entry>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Breadth-first_search&amp;diff=1629</id>
		<title>Breadth-first search</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Breadth-first_search&amp;diff=1629"/>
		<updated>2014-10-29T13:23:36Z</updated>

		<summary type="html">&lt;p&gt;Flomm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Algorithms]]&lt;br /&gt;
[[Category:Search Algorithms]]&lt;br /&gt;
[[Category:Tree Algorithms]]&lt;br /&gt;
[[Category:Graph Traversal]]&lt;br /&gt;
&lt;br /&gt;
== General information ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Algorithmic problem:&#039;&#039;&#039; [[Graph traversal]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Type of algorithm:&#039;&#039;&#039; loop&lt;br /&gt;
&lt;br /&gt;
== Abstract view ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Definition:&#039;&#039;&#039;&lt;br /&gt;
On this page, the &#039;&#039;&#039;distance&#039;&#039;&#039; of a node &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt; is the minimal number of arcs on a path from the start node &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Specific characteristic:&#039;&#039;&#039;&lt;br /&gt;
The nodes are finished in the order of increasing distance (which is not unique, in general).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Auxiliary data:&#039;&#039;&#039;&lt;br /&gt;
A [[FIFO queue]] &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; whose elements are nodes in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Invariant:&#039;&#039;&#039; &lt;br /&gt;
Before and after each iteration:&lt;br /&gt;
# There is a &#039;&#039;&#039;current distance&#039;&#039;&#039; &amp;lt;math&amp;gt;k\in\mathbb{N}&amp;lt;/math&amp;gt;.&lt;br /&gt;
# All nodes with distance at most &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; are already seen.&lt;br /&gt;
# Let &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denote the current size of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;. There is &amp;lt;math&amp;gt;\ell\in\{1,\ldots,n\}&amp;lt;/math&amp;gt; such that the first &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt; elements of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; have distance &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and the last &amp;lt;math&amp;gt;n-\ell&amp;lt;/math&amp;gt; elements have distance &amp;lt;math&amp;gt;k+1&amp;lt;/math&amp;gt; (in particular, &#039;&#039;all&#039;&#039; elements have distance &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; if, and only if, it is &amp;lt;math&amp;gt;\ell=n&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Variant:&#039;&#039;&#039; One node is removed from &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Break condition:&#039;&#039;&#039; &amp;lt;math&amp;gt;Q=\emptyset&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Induction basis ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Abstract view:&#039;&#039;&#039; The start node is seen, no other node is seen. The start node is the only element of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;. Both the output sequence and the arborescence &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; contain the start node &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and nothing else.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Implementation:&#039;&#039;&#039; Obvious.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Proof:&#039;&#039;&#039; Obvious.&lt;br /&gt;
&lt;br /&gt;
== Induction step ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Abstract view:&#039;&#039;&#039;&lt;br /&gt;
# Extract the first element &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Append &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; to the output sequence.&lt;br /&gt;
# For each outgoing arc &amp;lt;math&amp;gt;(v,w)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is not yet seen:&lt;br /&gt;
## Insert &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;(v,w)&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;.&lt;br /&gt;
## Label &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; as seen.&lt;br /&gt;
## Append &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Implementation:&#039;&#039;&#039; Obvious.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Proof:&#039;&#039;&#039;&lt;br /&gt;
The variant is obviously fulfilled. The first point of the invariant is only a notation, so nothing is to show for that.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;w\in V&amp;lt;/math&amp;gt; not yet seen before the current iteration, and let &amp;lt;math&amp;gt;(v,w)\in A&amp;lt;/math&amp;gt;. The induction hypothesis (second point of the invariant) implies that the distance of &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is greater than &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. However, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; has distance &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, so the distance of &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; cannot be greater than &amp;lt;math&amp;gt;k+1&amp;lt;/math&amp;gt;. Im summary, this proves the third point of the invariant.&lt;br /&gt;
&lt;br /&gt;
The critical iterations for the second invariant are those where &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; increases. These are exactly the iterations in which &amp;lt;math&amp;gt;\ell=1&amp;lt;/math&amp;gt; immediately before (and, consequently, &amp;lt;math&amp;gt;\ell=n&amp;lt;/math&amp;gt; immediately after) that iteration. All nodes with old distance &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; have been seen and no such node is in &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; anymore after the current iteration. Therefore, all nodes &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;(v,w)\in A&amp;lt;/math&amp;gt; have been seen as well. Clearly, this includes all nodes with old distance &amp;lt;math&amp;gt;k+1&amp;lt;/math&amp;gt;, in other words, the nodes with new distance &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Correctness ==&lt;br /&gt;
&lt;br /&gt;
It is easy to see that each operation of the algorithm is well defined. Due to the variant, the loop terminates after a finite number of steps. Based on a straightforward induction on the iterations, the third invariant ensures that the nodes leave &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; in ascending order of their distances.&lt;br /&gt;
&lt;br /&gt;
== Complexity ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Statement:&#039;&#039;&#039; The asymptotic complexity is in &amp;lt;math&amp;gt;\Theta(|V|+|A|)&amp;lt;/math&amp;gt; in the worst case.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Proof:&#039;&#039;&#039;&lt;br /&gt;
The complexity of each iteration is linear in the number of arcs leaving the current node &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Therefore, the complexity of the entire loop is in &amp;lt;math&amp;gt;\Theta(|A|)&amp;lt;/math&amp;gt; in the (worst) case when all nodes are reachable from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;.  The complexity of the initialization is dominated by the initialization of the seen labels of all nodes, which is clearly in &amp;lt;math&amp;gt;\Theta(|V|)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Remark ==&lt;br /&gt;
&lt;br /&gt;
The nodes in the queue form kind of a &amp;quot;frontier line&amp;quot;, which separates the nodes that already left &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; from the nodes that have not yet entered &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; so far.&lt;br /&gt;
More specifically, each path from some seen node to some unseen node contains at least one node that is currently stored in &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To see that, we apply a straightforward induction on the iterations. Let &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; be a path from some seen node outside &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; to some node that is not yet seen immediately after the current iteration. If &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; does not contain &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, the claim follows from the induction hypothesis. So assume &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; contains &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; be the last node on &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; that is already seen immediately after the current iteration. If &amp;lt;math&amp;gt;x=v&amp;lt;/math&amp;gt;, the claim follows from the fact that all unseen nodes &amp;lt;math&amp;gt;w\in V&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;(v,w)\in A&amp;lt;/math&amp;gt; were put in &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, so the immediate successor of &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is in &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; now. Otherwise, the claim follows from the induction hypothesis again.&lt;br /&gt;
&lt;br /&gt;
== Pseudocode == &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 BFS(&#039;&#039;G,s&#039;&#039;)&lt;br /&gt;
  1  &#039;&#039;&#039;for&#039;&#039;&#039; each vertex &#039;&#039;u&#039;&#039; &amp;amp;isin; &#039;&#039;G.V&#039;&#039; - {&#039;&#039;s&#039;&#039;}&lt;br /&gt;
  2       &#039;&#039;u.color&#039;&#039; = WHITE&lt;br /&gt;
  3       &#039;&#039;u.d&#039;&#039; = &amp;amp;infin;&lt;br /&gt;
  4       &#039;&#039;u.&#039;&#039;&amp;amp;pi; = NIL&lt;br /&gt;
  5  &#039;&#039;s.color&#039;&#039; = GRAY&lt;br /&gt;
  6  &#039;&#039;s.d&#039;&#039; = 0&lt;br /&gt;
  7  &#039;&#039;s.&amp;amp;pi;&#039;&#039; = NIL&lt;br /&gt;
  8  &#039;&#039;Q&#039;&#039; = &amp;amp;Oslash;&lt;br /&gt;
  9  ENQUE(&#039;&#039;Q, s&#039;&#039;)&lt;br /&gt;
 10  &#039;&#039;&#039;while&#039;&#039;&#039; &#039;&#039;Q&#039;&#039; &amp;amp;ne; &amp;amp;Oslash;&lt;br /&gt;
 11      &#039;&#039;u&#039;&#039; = DEQUEUE(&#039;&#039;Q&#039;&#039;)&lt;br /&gt;
 12      &#039;&#039;&#039;for&#039;&#039;&#039; each &#039;&#039;v&#039;&#039; &amp;amp;isin; &#039;&#039;G.Adj&#039;&#039;[&#039;&#039;u&#039;&#039;]&lt;br /&gt;
 13              &#039;&#039;&#039;if&#039;&#039;&#039; &#039;&#039;v.color&#039;&#039; == WHITE&lt;br /&gt;
 14                       &#039;&#039;v.color&#039;&#039; = GRAY&lt;br /&gt;
 15                       &#039;&#039;v.d&#039;&#039; = &#039;&#039;u.d&#039;&#039; + 1&lt;br /&gt;
 16                       &#039;&#039;v&#039;&#039;.&amp;amp;pi; = &#039;&#039;u&#039;&#039;&lt;br /&gt;
 17                       ENQUEUE(&#039;&#039;Q, v&#039;&#039;)&lt;br /&gt;
 18      &#039;&#039;u.color&#039;&#039; = BLACK&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Flomm</name></author>
	</entry>
</feed>