graph theory - What is meant by diameter of a network?

The diagram shown on this link of the "A graph with 6 vertices and 7 edges where the vertex no 6 on the far-left is a leaf vertex or a pendant vertex." has DIAMETER 4? right or wrong?Definitions are The diameter of a graph is the maximum eccentricity of any vertex in the graph. That is, it is the greatest distance between any pair of vertices. To find the diameter of a graph, first find the shortest path between each pair of vertices. The greatest length of any of these paths is the diameter of the graph. Diameter, D, of a network h...Read more

How to detect if adding an edge to a directed graph results in a cycle?

I came upon wait-for graphs and I wonder, are there any efficient algorithms for detecting if adding an edge to a directed graph results in a cycle?The graphs in question are mutable (they can have nodes and edges added or removed). And we're not interested in actually knowing an offending cycle, just knowing there is one is enough (to prevent adding an offending edge).Of course it'd be possible to use an algorithm for computing strongly connected components (such as Tarjan's) to check if the new graph is acyclic or not, but running it again ev...Read more

Shortest path from one vertex to another in a directed graph

My graph is directed and very large. The vertices in the graph represent towns, and the edges represents bus travel routes from town to town. The goal is to find a path from one vertex to another. It is very important that the algorithm takes into account the transfer time between buses.I would use Dijkstra's algorithm, but it goes from the whole graph and finds one way. I need to find a few of "the best" ways from vertex to vertex. By "the best" I mean with the shortest transfer times, but this is not the most important point....Read more

Graph vertex cover - same degree vertex confusion

In order to solve the graph vertex cover problem, I started with selecting the vertex v having the maximum degree and then deleting that vertex from the set of vertices and also deleting the edges having end point as v. I had a question that what if after deleting the above vertices and edges, I have more than one vertex that has the same degree, which vertex will my greedy algorithm choose?I tried searching online but could not find any suggestions for the above problem. If anybody can please help. Thanks...Read more

How can I determine if a directed graph has a path that consumes all edges starting from a certain node?

There's no restrictions that you have to cross each edge only once, or each vertex. Is there some property of the graph that is necessary and sufficient for the existence of such a path (like the degrees of nodes for the existence of the Eulerian path), or some known algorithm that proves there is or there isn't one (perhaps finding the minimum path through all edges from the starting one)?I have considered several possibilities, the strongest of which is collapsing strongly connected components into single supernodes, then check if the resulti...Read more

Computing numbers of simple path in directed graph containing cycles

I am interested in computing total number of simple paths(no node repeated) between two nodes in a graph(sparse, directed and contains cycles). The graph is a strongly connected component.I initially tried using matrix multiplication, where I raised the adjacency matrix to all powers from 2 through n-1, n being the number of nodes. However this fails because of cycles in graph. For a DAG just computing all these powers and summing them up will do the job....Read more

graph theory - Edge classification in a DFS

According to the book (Intro to Algorithm), in dfs, edges are classified as 4 kinds:Tree Edge, if in edge (u,v), v is first discovered, then (u, v) isa tree edge.Back Edge, if ......, v is discovered already and v is an ancestor, then it's a back edge.Forward Edge, if ......, v is discovered already and v is a descendant of u, forward edge it is.Cross Edge, all edges except for the above three.My question is how can I identify whether v is u's ancestor or descendant when I'm trying to figure out if (u, v) is a back or forward edge?...Read more

Add a edge to direct acyclic graph with other restrictions

I have a DAG. I have this operation to add a edge between two nodes.If A is reachable from B, then B is A's parent. If A is reachable from B without going though another node, then B is A's direct parent.Requirements for this graph are:No cycles.For any node, there is a list of direct parents P[1],P[2],P[3]... P[i] is not a parent of P[j] for any i and j. If adding a edge, requirement 1 is not met, the edge is not constructed.If adding a edge, requirement 2 is not met, the edge is constructed, but the direct parents will be modified in a way su...Read more

Graph Theory - How to find nodes reachable from a given node within certain cost?

I'm considering the following problem (very rough description):Assume we have a graph where edges are assigned some non-negative costs, a starting node s and some cost constant C. Find out:A set of nodes N, reachable from s where the cost of the shortest path from the starting node s to any node in N is not greater than C.For each e in the set the above - the cost of the shortest path.Basically Dijkstra with the cost constraint.My primary question is: what is the correct terminology in the graph theory for this problem?I've been looking at "acc...Read more

How can I find the minimum cut on a graph using a maximum flow algorithm?

I need to find the minimum cut on a graph. I've been reading about flow networks, but all I can find are maximum flow algorithms such as Ford-Fulkerson, push-relabel, etc. Given the max flow-min cut theorem, is it possible to use one of those algorithms to find the minimum cut on a graph using a maximum flow algorithm? How?The best information I have found so far is that if I find "saturated" edges i.e. edges where flow equals capacity, those edges correspond to the minimum cut. Is that true? It doesn't sound 100% right to me. It is true that a...Read more

graph theory - How do I use Breadth First Search to output the shortest path and not just tell me there is a path?

Im trying to create a program where i can add nodes and use a LinkedList to connect them. Once I have these connected nodes, I wanted to find the shortest path between them using Breadth First Search. Currently my program only finds whether of not there is a path, but i want to know what that path is. How should i modify my code? public static boolean findPath(String start, String destination){ //find the nodes given the String key Node current = getNode(start); Node end = getNode(destination); //cr...Read more

cycle - Directed acyclic graph through removing arches or reverting them

I have been struggling now with a way to formalize and throughouly prove the following: We are given the street network of a city. Prove that if we can remove all cycles in this network by creating at most p blockins, then we can remove all the cycles in the city network by reversing one way of at most p streets.Blocking means obstructing one way of the street. Reversing - (in case of a two-way street) means that one of the ways is inverted and then both ways are the same. Reversing (in case of a one-way street) means that the only way is inver...Read more

dataflow - More efficiently compute transitive closures of each dependents while incrementally building the directed graph

I need to answer the question: given a node in a dependency graph, group its dependents by their own transitive dependents which would be impacted by a particular start node.In other words, given a node in a dependency graph, find the set of sets of direct dependents which transitively have common dependents that derive from that particular starting node.e.g. given the pseudo code:let a = 1let b = 2let c = a + blet d = a + blet e = alet f = a + elet g = c + dYou could compute this graph:If we used a as the start node we can see that of the depe...Read more

breadth first search - Graph adjacency list giving wrong output

I have made a simple code to take number of vertices and number of edges as input, the take each edge and add it to the list of that vertex. However, I m not getting it right.#include <iostream>#include <list>using namespace std;int main(){ int t; cin>>t; while(t--) { int n,m; // number of vertices and edges cin>>n>>m; list<int> a[n]; list<int>::iterator it; while(m--) { int x,y; cin>>x>>y; // one edge x & y are vertices ...Read more