通过深度搜索在图中搜索周期
考虑以下搜索深度,为什么方法 check
in ProcessEdge 检测一个循环? 此代码遵循本书中显示的算法 Algortim Design Manual by S.Skiena. 检查是拼写错误,应该是
. 请询问任何解释。 我真的坚持下去。
UPDATE
修复了此代码的修复 errata
http://www.cs.sunysb.edu/~skie ... rrata
. 厘米。 /*/ p。 173, process_edge procedure - 正确的测试必须是
但它会检测到周期吗? 查看 if 永远不要经历,因为在方法中 DFS
只叫做
.
</int></int>
if/Parent[currVertex] != successorVertex/
in ProcessEdge 检测一个循环? 此代码遵循本书中显示的算法 Algortim Design Manual by S.Skiena. 检查是拼写错误,应该是
if/Parent[successorVertex] != currVertex/
. 请询问任何解释。 我真的坚持下去。
public void Search/int start/
{
/* NOTE: the differences from BFS are: this uses a stack instead of a queue AND this maintains 'time' variable */
Stack<int> s = new Stack<int>//;
int currVertex;
int successorVertex;
int time = 0;
s.Push/start/;
Discovered[start] = true;
while /s.Count != 0/
{
currVertex = s.Pop//;
// time increments every time we enter a node /when discovered/ and every time we exit a node /when processed_late, i.e. when all its neighbours have been processed/
time++;
EntryTime[currVertex] = time;
ProcessVertexEarly/currVertex/;
Processed[currVertex] = true;
for /int i = 0; i < Graph.Vertices[currVertex].Count; i++/
{
successorVertex = Graph.Vertices[currVertex][i].Y;
if /!Processed[successorVertex] || Graph.IsDirected/
{
ProcessEdge/currVertex, successorVertex/;
}
if /!Discovered[successorVertex]/
{
s.Push/successorVertex/;
Discovered[successorVertex] = true;
Parent[successorVertex] = currVertex;
}
}
// time increments every time we enter a node /when discovered/ and every time we exit a node /when processed_late, i.e. when all its neighbours have been processed/
time++;
ExitTime[currVertex] = time;
ProcessVertexLate/currVertex/;
}
}
private void ProcessEdge/int currVertex, int successorVertex/
{
if/Parent[currVertex] != successorVertex/ // then we've found a cycle
{
/* Found cycle*/
}
}
UPDATE
修复了此代码的修复 errata
http://www.cs.sunysb.edu/~skie ... rrata
. 厘米。 /*/ p。 173, process_edge procedure - 正确的测试必须是
if /discovered[y] && /parent[x] != y// { /* found back edge */
但它会检测到周期吗? 查看 if 永远不要经历,因为在方法中 DFS
process_edge
只叫做
discovered[y] == false
.
</int></int>
没有找到相关结果
已邀请:
1 个回复
龙天
赞同来自:
http://www.cs.sunysb.edu/~skie ... dfs.c
,
http://www.cs.sunysb.edu/~skie ... cle.c
和
http://www.cs.sunysb.edu/~skie ... rams/
. 代码Skien Gluchet. /尝试安排 3 2 1 2 2 3, 与两个肋骨的路径/, 所以,也许,一个翻身它的人 Java, 我试图修复一些东西。 不幸的是,恢复的版本也似乎是越野车,尽管没有完整的程序我无法确定它。
我相信,您分配的行的目的在下面组成。 在深度搜索
Neorientyrovan.
图表有两种类型的肋骨:
木头
和
背部
. 该图表具有循环,并且仅在存在后边缘时。 现在,皮肤所选择的非定向图形的呈现是将每个未定向弧的形式存储每个未定态的边缘,每个方向。 如果我们使用深度搜索以检测该导向图中的周期,那么两个长度循环,由对应于一个未定向的边缘的两个定向弧,与误差为循环通信。 正如书面,检查确保候选人的后退弧
不是弧面树
.