Skip to content

Commit

Permalink
Fix some links, beautify image layout
Browse files Browse the repository at this point in the history
  • Loading branch information
artagnon committed Jul 17, 2016
1 parent 376f473 commit 7a58e6c
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 10 deletions.
30 changes: 20 additions & 10 deletions _posts/2016-07-16-detecting-loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ algorithm. However, I'm going to discuss a definition of loop that admits
strange loops, but only things we'd intuitively call "loops".

With two loops, there are four reduced cases of strange loops:
![No loops](/assets/no-loops.png)
![Early Exit](/assets/early-exit.png)
![Multi-entry loop](/assets/multi-entry.png)
![Cuddled loops](/assets/cuddled-loops.png)

![No loops](/assets/no-loops.png) | ![Early Exit](/assets/early-exit.png)
:--------------------------------:|:-------------------------------------
*No loops* | *Early exit*


![Multi-entry loop](/assets/multi-entry.png) | ![Cuddled loops](/assets/cuddled-loops.png)
:-------------------------------------------:|:-------------------------------------------
*Multi-entry* | *Cuddled loops*

Now, let's employ a simple DFS:
{% highlight c++ %}
Expand All @@ -30,19 +35,24 @@ void DFS(Node *v) {
{% endhighlight %}

We get the following start times and end times:
![No loops](/assets/no-loops.png)
![Early Exit](/assets/early-exit.png)
![Multi-entry loop](/assets/multi-entry.png)
![Cuddled loops](/assets/cuddled-loops.png)

![No loops](/assets/no-loops-dfs.png) | ![Early Exit](/assets/early-exit-dfs.png)
:------------------------------------:|:-----------------------------------------
*No loops* | *Early exit*

![Multi-entry loop](/assets/multi-entry-dfs.png) | ![Cuddled loops](/assets/cuddled-loops-dfs.png)
:-----------------------------------------------:|:-----------------------------------------------
*Multi-entry* | *Cuddled loops*

Let's call the first number "DFS number", and the second number "topo number",
to indicate that this is the order that topological sort would have produced, in
the absence of backedges (topological sort is meaningless when there are loops).

First pass: number everything.

Second pass: find the backedge. When start_time[destination] <
start_time[source] and end_time[destination] > end_time[source], we have a
Second pass: find the backedge. When
`start_time[destination] < start_time[source]` and
`end_time[destination] > end_time[source]`, we have a
backedge from source to destination.

Third pass: find all the nodes in the loop. Here, we walk backwards from the
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions _posts/early-exit-dfs.gv
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ digraph {
"2/7" -> "3/6";
edge [label=backedge];
"4/5" -> "1/8";
edge [label=""];
"4/5" -> "3/6";
}
1 change: 1 addition & 0 deletions _posts/early-exit.gv
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ digraph {
body -> "exit target";
edge [label=backedge];
footer -> header;
edge [label=""];
footer -> "exit target";
}
File renamed without changes
File renamed without changes
Binary file modified assets/early-exit-dfs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/early-exit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7a58e6c

Please sign in to comment.