弦图的
perfect elimination
点排列
| INIT: g[][]
置为邻接矩阵
;
| CALL: cardinality(n); tag[i]
为排列中第
i
个点的标号
;
| The graph with the property mentioned above
| is called chordal graph. A permutation s = [v1 , v2,
| ..., vn] of the vertices of such graph is called a
| perfect elimination order if each vi is a simplicial
| vertex of the subgraph of G induced by {vi ,..., vn}.
| A vertex is called simplicial if its adjacency set
| induces a complete subgraph, that is, a clique (not
| necessarily maximal). The perfect elimination order
| of a chordal graph can be computed as the following:
\*==================================================*/
procedure maximum cardinality search(G, s)
for
all vertices v of G
do
set label[v] to zero
end
for
for
all i from n downto 1
do
choose an unnumbered vertex v with largest label
set s(v) to i{number vertex v}
for
all unnumbered vertices w adjacent to vertex v
do
increment label[w] by one
end
for
end
for
end procedure
int
tag[V], g[V][V], deg[V], vis[V];
void
cardinality(
int
n)
{
int
i, j, k;
memset(deg, 0,
sizeof
(deg));
memset(vis, 0,
sizeof
(vis));
for
(i = n - 1; i >= 0; i--) {
for
(j = 0, k = -1; j < n; j++)
if
(0 == vis[j]) {
if
(k == -1 || deg[j] > deg[k]) k = j;
}
vis[k] = 1, tag[i] = k;
for
(j = 0; j<n; j++)
if
(0 == vis[j] && g[k][j]) deg[j]++;
}
}