Vertices dominating over a particular vertex in the graph - data-structures

In the above graph, which vertices dominating over vertex 6?

Answer is 0,1,2,3,4,5.
A vertex A is said to be dominating over vertex B, only if there is path from the entry node to B that is going through vertex A. In above question, only vertex 7 cannot lie in the path from any source vertex to destination,that is vertex 6.

Related

Directed Weighted Graph with required vertices

Given: A directed, weighted graph G=(V, E), some of the vertices are red, some blue, and the rest white, weight Ti which is the maximum weight allowed to go from any vertex red vertex to any blue vertex.
Problem: Create an algorithm that finds a path from source node S, to target node T with least weight and which at some point goes from a red vertex to a blue vertex in at most Ti weight before reaching vertex T. The algorithm should have time complexity O(n^3)
Comments: I'm not sure how to get started on this, I figure it's some variation of Dijkstra's algorithm and I've seen some people talking about making copies of the graphs and connecting the copies but beyond that, I'm not sure what the setup of this algorithm would look like. Any help would be appreciated.
Indeed, you can use the copy-strategy as follows:
Copy the graph G to G' and to G". Label all vertices in G' as in G, but with the apostrophe. So there is an S' and a T' in G'. Similarly, S" and T" belong to G".
Let S be the start vertex, and T" be the target. As it stands now, G, G' and G" are disconnected. But add the following zero-weight, directed edges:
Edges from each red vertex r in G, to its mirror r' in G'.
Edges from each blue vertex b' in G', to its mirror b" in G".
So there are no paths from G" to G', nor from G' to G, nor from G" to G.
Now start a Dijkstra algorithm in S, with an additional data attribute for each entry in the priority queue: the weight that a path accumulated by edges in G' only. Let's call this w'. This w' plays no role in the priority of the queue. The total weight of a path determines the priority as is standard in Dijkstra's algorithm. The algorithm should not expand paths whereby w' would exceed Ti. Besides that specific limitation, all the rest of the algorithm can remain as in the standard Dijkstra algorithm.

Vertex with minimal distance to n other vertices

Given a directed, weighted, cyclic graph, and minimal path distance between vertices given by m(x,y), find the vertex v that minimises m(a,v) + m(b,v) + m(c,v) + ... for n vertices a, b, c...
For example if the graph was undirected and we wanted the vertex v with minimal paths to vertices a and b, v would just be the vertex in the centre of the minimal path from a to b.
I can imagine an approach involving depth traversal etc, but wanted to ask what SO would suggest - Thanks hope this was clear.
Now that I am thinking a bit more about it, you should probably look at Bidirectional Search.
The basic idea would be to start a Dijkstra from each of your query nodes (a, b, c, ...) at the same time. The first vertex that is found by all of them is your result vertex.
You can implement this by putting all (unvisited vertex, distance, query vertex)triplets you encounter in one priority queue (sorted by distance) and process it similar to Dijkstra. You will need to label the the vertices you have seen with the query node from which you reached them. When a vertex is labeled with all query vertices then this is your result (let's call it median vertex).

A graph, G, has a minimum vertex cover of size |V| - 1 if and only if G is complete. Is it true?

A mesh can be an example of a complete G. Where each node is connected to every other node. So shouldn't the minimum vertex cover size for such a graph is '1'.
Minimum vertex cover is the set of vertices such that every edge is touching a vertex in the set. Given a mesh (complete graph) of A B and C, if you only have one node (say A) as your attempted MVC, you're missing an edge (in this case the edge B-C).

Minimum sum of distances from sensor nodes to all others

Is there a way to compute (accurate or hevristics) this problem on medium sized (up to 1000 nodes) weighted graph?
Place n (for example 5) sensors in nodes of the graph in such way that the sum of distances from every other node to the closest sensor will be minimal.
I'll show that this problem is NP-hard by reduction from Vertex Cover. This applies even if the graph is unweighted (you don't say whether it's weighted or not).
Given an unweighted graph G = (V, E) and an integer k, the question asked by Vertex Cover is "Does there exist a set of at most k vertices such that every edge has at least one endpoint in this set?" We will build a new graph G' = (V', E), which is the same as G except that all isolated vertices have been discarded, solve your problem on G', and then use it to answer the original question about Vertex Cover.
Suppose there does exist such a set S of k vertices. If we consider this set S to be the locations to put sensors in your problem, then every vertex in S has a distance of 0, and every other vertex is at a distance of exactly 1 away from a vertex that is in S (because if there was some vertex u for which this wasn't true, it would mean that none of u's neighbours are in S, so for each such neighbour u, the edge uv is not covered by the vertex cover, which would be a contradiction.)
This type of problem is called graph clustering. One of the popular methods to solve it is the Markov Cluster (MCL) Algorithm. A web search should provide some implementation examples. However it does not generally provide the optimal solution.

Transform a simple directed graph to a simple undirected graph

How would I convert a simple directed graph to a simple undirected one?
Is this possible?
Assuming: (from here)
in a simple digraph loops are disallowed. (A loop is an arc that pairs a vertex to itself.)
and: (from here)
a simple [undirected] graph is an undirected graph that has no loops (edges connected at both ends to the same vertex) and no more than one edge between any two different vertices.
I'm assuming the edges are unweighted, otherwise this can't be done without specifying how this needs to be done.
AM = Adjacency matrix
AL = Adjacency list
Remove the direction of all edges.
AM: For each edge A->B, row A, column B would already be set. Also set row B, column A.
AL: For each edge A->B, the edge already appears in A's AL, also add the edge to B's AL.
Go through all edges, removing all edges for which we already found an edge between the two vertices that are the end-points of that edge (so if A-B has already been processed, if we find another A-B (or equivalently B-A), we must remove that edge). This needs to be done since there can be multiple edges between vertices in a simple directed graph, but this can't happen in a simple undirected graph.
AM: Nothing really needs to be done since an AM forces there to only be a single edge between vertices, so we'd just be overwriting the edges.
AL: For each vertex A, for each edge A-B or B-A in its adjacency list, remove all other edges A-B or B-A in the list.
Source and details...
For each directed edge e=(x,y), add new vertices ve1,…,ve5 and replace e with the edges xve1, ve1ve2, ve1ve3, ve3ve4, ve4ve5, ve3y.
To decode, every leaf (degree-1 vertex) whose neighbour has degree 2 must be ve5 for some edge e=(x,y); its neighbour is ve4 and the other neighbour of ve4 is ve3. ve3 has a unique neighbour that has both degree 3 and is adjacent to a leaf: the neighbour is ve1 and its leaf is ve2 (if ve1 has two leaf neighbours, pick one arbitrarily to be ve2). The other neighbour of ve1 is x and the other neighbour of ve3 is y. Restore the directed edge (x,y) and delete the vertices ve1,…,ve5.
G=(V,E) is a directed graph. (a,b) \in E is a directed edge.
G' = (V, E') is an equivalent undirected graph where (a,b) is transformed as (a,b) and (b,a).
Thus, edge directed edge becomes two edge (one in each direction).

Resources