【发布时间】:2013-05-25 20:01:00
【问题描述】:
考虑是否可以使用 BFS 实现图形着色,我想出了下面伪代码的方法。
虽然它看起来像一个贪心算法,但我不确定它的正确性。有没有高手cmet?
colors[MAX_COLORS];
colorsUsedSoFar[] = NIL;
like BFS, color first node u with colors[0] i.e color[u] = colors[0];
colorsUsedSoFar[] += colors[0];
for each node v adjacent to u{
(if v not already colored){
color[v] = color from the colorsUsedSoFar[] but NotUsedByItsAdjacents
If all the colors in colorsUsedSoFar[] are used by adjacents, assign a new color to v)
}
}
“像 BFS”是指使用队列并处理直到队列耗尽。
【问题讨论】:
-
"but NotUsedByItsAdjacents"显然使它“正确”,因为这是您要遵守的要求。除非您的意思是使用的最佳/最少颜色,否则它与Wikipedia 不同。
标签: algorithm graph-algorithm graph-coloring