Starting from:

$26

CS590 homework 6 Graphs, and Shortest Paths Solved

Develop a data structure for directed, weighted graphs G = (V, E) using an adja­cency matrix representation.. The d.atatype int is used to store the weight of edges. int does not allow one to represent ±co. Use the values INTYIN and IN'T_MAX (defined in limits .h) instead.

include <limits-h5 in.t d, e;

d = INT_MAX;

e = INT_MIN;

if (e == ih-r_mir;)

if (d I = IN-1_102A10           .

1. Develop a function random_graph that generates a random graph G = (Vt if). with n. vertices and -m. edges taping the weights (integers values) at random out of the interval [—w, w]. In order to have a more natural graph we generate a series of random paths tb, vi, - , vir, through the graph. Each of the individual paths has to be non-cyclic. The combination of the random paths might contain a cycle. The edges used in the series of random paths has to add up to the desired m edges.

Notes:

§  Determine the number of maximal allowed edges for a non-cyclic random path LIG, 121,

·    How do you ensure that the path is random? A random permutation of the vertices might be useful.

·    How do Mo. random path that cross each other (share one or more edges effect the overall edge count? Shared edges should be counted only once.

2.      Describe (do not implement) how you would update the above implemented random_graph method to generate a graph G = ( V, E) that does not contain a negative-weight cycle. You are given a. function that. can determine whether or not an edge completes a negatice-weight cycle.

3. Implement the Gellman-Ford algorithm. What is the running time for Gellman-Ford using an adjacency matrix representation?

Implement the Floyd-Warshall algorithm. Your inwlementation should pro­duce the shortest weight matrix DO) and the predecessor matrix II("). Limit the number of newly 

More products