Question

In: Computer Science

modify Graph to disallow parallel edges and self loops.

modify Graph to disallow parallel edges and self loops.

Solutions

Expert Solution

You can trivially transform your graph to one without single-edge loops and parallel edges.

With single-edge loops you need to check whether their weight is negative or non-negative. If the weight is negative, there obviously is no shortest path, as you can keep spinning in place and reduce your path length beyond any limit. If however the weight is positive, you can throw that edge away, as no shortest path can go through that edge.

A zero-weight edge would create a similar problem than any zero-weight loop: there will be not one but an infinite number of shortest paths, going through the same loop over and over again. In these cases the sensible thing is again to remove the edge from the graph.

Out of the parallel edges you can throw away all but the one with the lowest weight. The reasoning for this is equally simple: if there was a shortest path going through an edge A that has a parallel edge B with lower weight, you could construct an even shorter path by simply replacing A with B. Therefore no shortest path can go through A.

Related Solutions

A graph consists of nodes and edges. An edge is an (unordered) pair of two distinct...
A graph consists of nodes and edges. An edge is an (unordered) pair of two distinct nodes in the graph. We create a new empty graph from the class Graph. We use the add_node method to add a single node and the add_nodes method to add multiple nodes. Nodes are identified by unique symbols. We call add_edge with two nodes to add an edge between a pair of nodes belonging to the graph. We can also ask a graph for...
A graph consists of nodes and edges. An edge is an (unordered) pair of two distinct...
A graph consists of nodes and edges. An edge is an (unordered) pair of two distinct nodes in the graph. We create a new empty graph from the class Graph. We use the add_node method to add a single node and the add_nodes method to add multiple nodes. Nodes are identified by unique symbols. We call add_edge with two nodes to add an edge between a pair of nodes belonging to the graph. We can also ask a graph for...
Graph Theory: Let S be a set of three pairwise-nonadjacent edges in a 3-connected graph G....
Graph Theory: Let S be a set of three pairwise-nonadjacent edges in a 3-connected graph G. Show that there is a cycle in G containing all three edges of S unless S is an edge-cut of G
Consider the parallel planes of infinite extent normal to the page having opposite edges. The planes...
Consider the parallel planes of infinite extent normal to the page having opposite edges. The planes are in the environment of Tenv = 300 K as shown Using the appropriate view factor relations and the result for the opposing parallel planes, develop an expression for the view factor, F1?2 Using the cross-string technique to determine the view factor, F1?2 Calculate temperature Tl
Modify the following code to use ONLY pointer arithmetic (no array expressions) and no for loops...
Modify the following code to use ONLY pointer arithmetic (no array expressions) and no for loops to do the same thing this code does. Be sure that you understand how the code works and how the pointer arithmetic relates to the array expression form. Provide liberal comments to explain what your pointer arithmetic is computing. #include <stdlib.h> #include <stdio.h> int main(int argc, char **argv) { int arg_count = 0; for (arg_count = 0; arg_count < argc; arg_count++) printf("%s\n", argv[arg_count]); }
Prove a connected simple graph G with 16 vertices and 117 edges is not Eulerian.
Prove a connected simple graph G with 16 vertices and 117 edges is not Eulerian.
Is it possible for a planar graph to have 6 vertices, 10 edges and 5 faces?...
Is it possible for a planar graph to have 6 vertices, 10 edges and 5 faces? Explain.
5. Suppose we are given both an undirected graph G with weighted edges and a minimum...
5. Suppose we are given both an undirected graph G with weighted edges and a minimum spanning tree T of G . (a) Describe an algorithm to update the minimum spanning tree when the weight of a single edge e is decreased. (b) Describe an algorithm to update the minimum spanning tree when the weight of a single edge e is increased. In both cases, the input to your algorithm is the edge e and its new weight; your algorithms...
Draw a connected, simple graph with 6 vertices and 12 edges. Verify the Handshaking Lemma for...
Draw a connected, simple graph with 6 vertices and 12 edges. Verify the Handshaking Lemma for your graph.
1.  Prove that for any graph, the sum the degreesPv∈V deg(v) is twice the number of edges...
1.  Prove that for any graph, the sum the degreesPv∈V deg(v) is twice the number of edges |E|. (By “prove” I mean write a few sentences explaining why it is true.) 2. i) At a recent math seminar, 5 mathematicians greeted each other by shaking hands. Is it possible for each mathematician to shake hands with exactly 3 other people? (No one can shake his or her own hand.) To answer the question, please rephrase the problem as a problem about...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT