I'm new to Mathematica and I'm attempting to write an approximation algorithm to compute "maximum" independent sets. What I need to do is given a graph g to remove its vertex of minimum degree and its neighbors.
I've managed to do so with the following code:
remmdv[g_] := VertexDelete[g, VertexList[NeighborhoodGraph[g, Ordering[VertexDegree[g], 1]]]]
The Ordering gets the vertex of minimum degree and by converting NeighborhoodGraph to a VertexList I can remove these vertices from g.
This I've managed to sort out and it seems to work properly.
The thing is that the following function throws an error when I run it.
approx[g_] := (
n = 0;
While[Not[EmptyGraphQ[g]], n++; g = remmdv[g]];
Return[n];
);
I'm not familiar with functions in Mathematica and maybe what I wrote makes no sense, but it's what seems reasonable coming from an imperative programming background.
Thanks to all of you in advance.
