Gid*_*eon 2 algorithm pseudocode graph-algorithm
所述布隆-Kerbosch算法是用于列出的图表的所有极大派系的方法。我最近只是为了好玩而成功地实现了该算法。缺点是该算法是递归的,因此只能在很小的图上运行,直到堆栈溢出为止。
应该有可能使算法纯粹是迭代的。考虑一下Wikipedia上的基本版本(无限制)。该算法的迭代版本在伪代码中的外观如何?某处有描述吗?
我在想象一个堆栈数据结构来模拟递归。我还应该有一个循环,在其中测试P和X的空度,但是我没有看到完整的答案。
BronKerbosch1(R, P, X):
if P and X are both empty:
report R as a maximal clique
for each vertex v in P:
BronKerbosch1(R ? {v}, P ? N(v), X ? N(v))
P := P \ {v}
X := X ? {v}
Run Code Online (Sandbox Code Playgroud)
为了模拟递归,我们只需要使用堆栈来跟踪三个变量:
BronKerbosch(P):
S := empty stack
S.push({}, P, {})
while S is not empty:
R, P, X := S.pop()
if P and X are both empty:
report R as a maximal clique
if P is not empty:
v := some vertex in P
S.push(R, P \ {v}, X ? {v})
S.push(R ? {v}, P ? N(v), X ? N(v))
Run Code Online (Sandbox Code Playgroud)