I know that in an undirected graph you have to have at least three vertices to form a cycle. My question is, in a directed graph, is it considered a cycle if two vertices have two edges pointing to each other?
Here is an example:
Is this a cyclic graph?
Related questions:
In an undirected graph, the simplest cycle must have 3 nodes?
Existence of cycle between any two vertices of graph
Cycles in an Undirected Graph
A graph has a cycle if there is a non-empty path that originates at some vertex and ends at the same vertex. In your graph above, you have a cycle on path A -> C -> A. Similarly, let's imagine a directed graph with 2 vertices A and B and 2 edges AB and BA (where the first letter is the source vertex). This means that there is a cycle A -> B -> A, thus you can have a cycle in a directed graph of 2 vertices.
I would say it (A-C-A) is a cycle. But I am from a different perspective: you may know that for a directed acyclic graph (dag), there is a topological sorting on it; otherwise, there isn't.
Topological sorting is indeed the linear extension of a partial order <=. Thus, dag is the graphical representation of a partial order <=. Be aware that according to the anti-symmetry property of a partial order <= (i.e., if a<=b and b<=a, then a=b), there is no possibility that two edges (a,b) and (b,a) simultaneously exist between two distinct vertices a and b.
In summary, no cycle => exists topological sorting, since no topological sorting on your digraph, thus there must be a cycle (A-C-A).
No,it is not considered a cycle if two vertices have two edges pointing to each other in directed graph. They are called Parallel Edges.
According to this definition 1:
A circuit is a closed trail with at least one edge
A-C is considered a circuit.
A-C also complies with this definition2:
A cycle is a circuit in which no vertex except the first (which is
also the last) appears more than once.
so it is also a cycle.
1 source: https://proofwiki.org/wiki/Definition:Circuit
2 source: https://proofwiki.org/wiki/Definition:Cycle_(Graph_Theory)
Related
I'm taking the Algorithms: Design and Analysis II course, and one of the questions is as follows:
Consider a connected undirected graph with distinct edge costs. Which
of the following are true? [Check all that apply.]
Suppose the edge 𝑒 is not the cheapest edge that crosses the cut (𝐴,𝐵). Then 𝑒 does not belong to any minimum spanning tree.
Suppose the edge 𝑒 is the most expensive edge contained in the cycle 𝐶. Then 𝑒 does not belong to any minimum spanning tree.
The minimum spanning tree is unique.
Suppose the edge 𝑒 is the cheapest edge that crosses the cut (𝐴,𝐵). Then 𝑒 belongs to every minimum spanning tree.
To my knowledge, all four options are correct. Options 1, 2 and 4 follow from the Cut property; option 3 is correct because edge weights are distinct. However, including option 1 is turning out to be wrong. Why?
No
Yes
Yes
Yes
The main part here is to answer #3. For a graph with all distinct edge costs that is true. Answers for all other questions you can derive using answer to the third one.
For #1:
A1 --- B1
|
A2 --- B2
Suppose w(A1,B1) > w(A2,B2), but you still need to include both of them into MST.
First of all lets look at the mst definition.MST is a subset of a connected undirected graph with distinct edge costs that connects all the vertices together, without any cycles and with the minimum possible total edge weight.
1.If the edge e is the only way to traverse A to B without causing a cycle it may belong to a mst.
2.If there is a cycle C then we can't talk about mst it will be a closed path.That is the definition of the cycle.
3.If each edge has a distinct cost as you mentioned then there will be only one, unique minimum spanning tree.
4.It may not because it can cause a loop like cycle or circuit then we don't use that edge to traverse A to B
Regarding weighted graphs:
If there is a weight 3 from A->B and a weight 1 from B->A, does this mean that there are 2 edges between A and B? I'm 95% sure that the answer is yes, but I'd like to be certain. I'm trying to see if directed graphs with weight schemes like this are automatically multigraphs.
Thanks for your valuable input!
Marcus
As noted here
A graph with one edge from A to B and one edge from B to A, will simply be called a directed graph, but if we would have a directed graph with multiple edges from A to B, it will be called as multigraph or specifically, in our case, multidigraph.
Like, in the diagram(taken from same link).
In the first graph, there is no case when we have two edges from same origin and destination, so its a normal directed graph. But in case of second graph, there are two edges from e to d and from b to c. Thus, making it a multidigraph.
There are 2 edges between A and B, but they are not the same edge in a directed graph. There is the edge from A to B (A->B) and the edge from B to A (B->A). This does not make the graph a multigraph because those are two distinct edges.
In an undirected multigraph the source and destination nodes do not matter. The edges would no longer be (A->B) and (B->A) . They would simply each become (A, B) indicating an edge between A and B exists. If more than one edge connects any two nodes in an undirected graph, the graph becomes a multigraph.
A Direcited Multigraph must have multiple edges with the same source and destination. If there were multiple edges from A to B, then it would be a directed multigraph. However, you list two distinct directed edges. (A->B) and (B->A). These edges are not identical and so the graph you describe is not a multigraph.
Why a complete, directed graph G on n vertices and m edges has m = n(n-1) edges. But I tried lots of examples showing this statement is false, which would be n(n-1)/2 But our professor gives true to this statement. Can someone explain to me the correctness of this statement?
I think you haven't completely understood the difference between directed and undirected graphs.
Remember in an undirected graph, the orientation of the edges doesn't matter.
But in directed graphs, the orientation of edges matter.
As an analogy, suppose the two cities, A and B are represented by two nodes of a graph, and the path joining them represents the edge. Now if the edge is un-directed, you can go from A to B or vice versa. However if it's directed, it means that it's a one way road, you can only go from A to B or vice versa (depending on the orientation).
Now to answer your question, in an undirected graph, the total number of edges would be
C(n,2) = (n*(n-1))/2.
But in a directed graph of n nodes, every edge can be doubled up. i.e, One from A to B and other from B to A.
Hence, the total number of edges = 2*C(n,2)
Which translates to n*(n-1).
You are talking about directed graph, so between two nodes A and B, you can have one directed edge from A to B and one from B to A.
Knowing that, you can find the expected result by induction.
I have been through multiple definitions of DAG and all of them say that it is a directed graph without cycles. Also, it is said that it has topological ordering.
Now the following figure is directed graph and does not have cycles.
But looking at the ordering of edges (look at edge (2,1)), it is not topologically ordered.
Is this still a DAG or every edge must be topologically ordered for this graph to be a DAG??
Yes this is a DAG. To check: you cannot go from one node and reach it again following the edges in the graph. As a matter of fact, the graph is complete directed acyclic graph in a sense that it holds the maximum number of possible edges in a DAG of 3 nodes. Adding any new edge would turn it into a cyclic digraph.
For complete DAGs, there is only one topological order. In your case it is 0>2>1.
An informal way to generate a topological ordering:
pick the source -- the one with zero incoming edges (in case there
are many, choose anyone).
Remove it from the graph (with its outgoing edges of course).
Repeat until you end up with empty graph.
I would like to list all the cycles in an undirected multigraph.
Tarjan's strongly connected components algorithm was written for a directed graph. Will it work for multigraphs? If not, is there an cycle listing algorithm for undirected multigraphs?
There are a few ways to reduce your problem to Tarjan, depending on how you want to count cycles.
First, apply two transformations to your graph:
Convert to a directed graph by replacing each undirected edge with a pair of opposing directed edges.
For each pair of nodes, collapse edges pointing the same direction into a single edge.
You'll be left with a directed graph. Apply Tarjan's algorithm.
Now, depending on what you consider a cycle, you may or may not be done. If a cycle is set of nodes (that happen to posses the required edges), then you can read the cycles directly off the transformed graph.
If a cycle is a set of edges (sharing the required nodes), then you need to "uncollapse" the edges introduced in step 2 above. For each collapsed edge, enumerate along the set of real edges it replaced. Doing so for each edge in each collapsed cycle will yield all actual cycles in a combinatorial explosion. Note that this will generate spurious two-cycles which you'll need to prune.
To illustrate, suppose the original graph has three nodes A, B and C, with two edges between A and B, one between B and C and one between A and C. The collapsed graph will be a triangle, with one cycle.
Having found a cycle between the three nodes, walk each combination of edges to recover the full set of cycles. Here, there are two cycles: both include the A to C and B to C edges. They differ in which A to B edge they choose.
If the original graph also had two edges between B and C, then there would be four expanded graphs. The total number of expanded cycles is the product of the edge counts: 4 == 2 * 2 * 1.