Split undirected graph by negative edges - graph

Wondering if there exists an algorithm to split an undirected connected component graph given negative edges.
Essentially the vertices provided in negative edges should be unreachable.

If you want the connected components of your graph that contains only positive edges, then first delete all negative edges from your graph. Then run a DFS (depth-first-search) to find all connected components.
Here is the algorithm.
Begin
For each edge e in graph G, if e is negative, remove e from G.
For each vertex v in G, do:
If v is not labeled as visited
Let c be a new component, and add c to set C.
Call procedure DFS(v, c) to find one component of positive edges only.
End If
End For
The set C contains all the connected components consisting of positive edges only.
End
Procedure DFS(v, c)
Add v to c, and label v as visited.
For each edge from v to w, do
If vertex w is not labeled as visited then
Call DFS(G,w)
End If
End For
End Procedure

Related

Subgraph in LightGraphs - Julia

Say that I have a big network with 10^4 nodes. And then I want to analyse the neighbourhood associated with a random node, say node 10. I can see which are the nodes connected to that node by looking at the 10th row entries of the adjacency matrix, and then I can repeat this if I want to look at the neighbours of those neighbours (second shell) and so on and so forth.
Is there an efficient way to do this - or even an inefficient but better than writing the whole thing from the scratch-? The actual network that I have is a Random Regular Graph and I am interested on the tree-like local structure for large networks.
If I understand your use case, there is a good way of doing this: the egonet function. You give it a graph, a starting vertex, and number of hops, and it will return an induced subgraph of the graph starting at the vertex and going out that number of hops. Here's the docstring:
egonet(g, v, d, distmx=weights(g))
Return the subgraph of g induced by the neighbors of v up to distance d, using weights (optionally) provided by distmx. This is equivalent to
induced_subgraph(g, neighborhood(g, v, d, dir=dir))[1].
Optional Arguments
––––––––––––––––––––
• dir=:out: if g is directed, this argument specifies the edge direction
with respect to v (i.e. :in or :out).
Edited to add: if all you need are the vertex indices, then neighborhood() is what you want:
neighborhood(g, v, d, distmx=weights(g))
Return a vector of each vertex in g at a geodesic distance less than or equal to d, where distances may be specified by distmx.
Optional Arguments
––––––––––––––––––––
• dir=:out: If g is directed, this argument specifies the edge direction
with respect to v of the edges to be considered. Possible values: :in or :out.

Given a graph G = (V, E) prove e <= n(n-1)/2 for all n

I'm trying to figure out to solve this problem: Given a graph G = (V, E) prove e <= n(n-1)/2 for all n, where e is the number of edges and n is the number of vertices.
I'm thinking that I should somehow be using math induction to figure out the correct answer and use n = 1 or 0 for my hypothesis, but I'm getting a little stuck on what to do after -- if I assume n = k, then: e <= (k+1)k/2. and if n = k+1 then e <= k(k-1)/2.
As I understand it, each vertex has n-1 possible edges coming out, and there are n total vertices, which is where n(n-1) comes from and dividing by 2 gets rid of the repeats. But I am unsure how I am to prove this.
The statement is false for multi-graphs. Take the graph:
/---\
O-----O
There are two vertices (O) and two edges; therefore n=2,e=2 and substituting into n(n-1)/2 <= e gives 1 <= 2 which is false.
However, if you restrict the graph to be simple - disallowing looping edges (where both ends of the edge terminate at the same vertex), multi-edges (where two edges connect the same pair of vertices) and that the graph is undirected - then the property holds.
Consider a complete graph K_n (with n vertices): each of the n vertices is incident to the other n-1 vertices via a connecting edge therefore there are n(n-1) connections from one vertex to another; given that edges are undirected then this will count each edge twice (i.e counting from vertex A to vertex B and vice versa) then the total number of edges will be n(n-1)/2.
Any graph G_n (with n vertices) will be a sub-graph of K_n (since you cannot add any more edges to K_n without creating multi- or looping edges) then there must be equal or fewer edges in G_n than in K_n.
Thus e <= n(n-1)/2 for all simple graphs.
If you further restrict the graph to be planar then you can state that e <= 3n - 6 (when n > 2).

cycle 'cover' that contain an edge in a digraph

I am wondering whether there exists a fast algorithm for the following problem. Given a digraph G, possibly with loops (that is edges that begin and end at the same vertex) and the choice of an edge e in G, what is the largest (in terms of number of vertices) subgraph of G that contains e and admits a vertex disjoint cycle cover.

Bipartite connected graph proof

A friend presented me with a conjecture that seems to be true but neither of us can come up with a proof. Here's the problem:
Given a connected, bipartite graph with disjoint non-empty vertex sets U and V, such that |U|<|V|, all vertices are in either U or V, and there are no edges connecting two vertices within the same set, then there exists at least one edge which connects vertices a∈U and b∈V such that degree(a)>degree(b)
It's trivial to prove that there is at least one vertex in U with degree higher than one in V, but to prove that a pair exists with an edge connecting them is stumping us.
For any edge e=(a,b) with a∈U and b∈V, let w(e)=1/deg(b)-1/deg(a). For any vertex x, the sum of 1/deg(x) over all edges incident with x equals 1, because there are deg(x) such edges. Hence, the sum of w(e) over all edges e equals |V|-|U|. Since |V|-|U|>0, w(e)>0 for som edge e=(a,b), which means that deg(a)>deg(b).
Prove it by contradiction, i.e. suppose that deg(a) ≤ deg(b) ∀(a,b)∈E, where E is the edgeset of the graph (with the convention that the first element is in U and the second in V).
For F⊆E, designate by V(F) the subset of V which is reachable through edgeset F, that is:
V(F) = { b | (a,b)∈F }
Now build an edgeset F as follows:
F = empty set
For a ∈ U:
add any edge (a,b)∈E to F
Keep adding arbitrary edges (a,b)∈E to F until |V(F)| = |U|
The set V(F) obtained is connected to all nodes in U, hence by our assumption we must have
∑a∈U deg(a) ≤ ∑b∈V(F) deg(b)
However, since |U|=|V(F)| and |U|<|V| we know that there must be at least one "unreached" node v∈V\V(F), and since the graph is connected, deg(v)>0, so we obtain
∑a∈U deg(a) < ∑b∈V deg(b)
which is impossible; this should be an equality for a bipartite graph.

Proof that Dominating Set is NP-Complete

here is the question. I am wondering if there is a clear and efficient proof:
Vertex Cover: input undirected G, integer k > 0. Is there a subset of
vertices S, |S|<=k, that covers all edges?
Dominating Set: input undirected G, integer k > 0. Is there a subset of
vertices S, |S|<= k, that dominates all vertices?
A vertex covers it's incident edges and dominates it's neighbors and itself.
Assuming that VC is NPC, prove that DS is NPC.
There is a quite nice and well known reduction:
Given an instance (G,k) of Vertex Cover build an instance of Dominating Set (H,k), where for H you take G, remove all isolated vertices, and for every edge (u,v) add an additional vertex x connected to u and v.
First realize that a Vertex Cover of G is a Dominating Set of H: it's a DS of G (after removing isolated vertices), and the new vertices are also dominated. So if G has a VC smaller k, then H has a DS smaller k.
For the converse, consider D, a Dominating Set of H.
Notice that if one of the new vertices is in D, we can replace it with one of it's two neighbors and still get an Dominating Set: it's only neighbors are are the two original vertices and they are also connected - everything x can possible dominate is also dominated by u or v.
So we can assume that D contains only vertices from G. Now for every edge (u,v) in G the new vertex x is dominated by D, so either u or v is in D. But this means D is a Vertex Cover of G.
And there we have it: G has a Vertex Cover smaller k if and only if H has a Dominating Set smaller k.
Taken from :
CMSC 651 Advanced Algorithms , Lecturer Samir Khuller
I think that second problem is not NP.
Let's try the following algorithm.
1. Get the original Graph
2. Run any algorithm which checks if a graph is connected or not.
3. mark all used edges of step 2
4. if the graph is connected then return the set of marked edges otherwise there is no such a set.
If I understood correctly your problem then it is not NP Complete.

Resources