MATLAB: Approximate vertex cover problem

coververtex

Hello, I have 2 question: I want you resolve Approximate vertex cover problem, therefore
1.Can someone give me function who will choice random edge(2 vertex, ex: u and v) in graph, 2.And then function who will delete all egdes incident on either u and v.
Thank you!

Best Answer

Assuming you've got an incidence matrix A with A(u,v) if there is an edge from u to v, then a random edge could be selected with
i = randsample(find(A),1);
[u,v] = ind2sub(size(A),i);
and then delete the edges with
A(u,:) = 0; % edges from u
A(:,u) = 0; % edges to u
A(v,:) = 0;
A(:,v) = 0;
This is probably not the most efficient algorithm but if the number of vertices is large then it should run a lot faster if you make A a sparse array.