Question

you to develop object oriented programs of a graph that can achieve the following functions l. A graph can be empty with no vertex or edge. 2. A graph can be either a directed graph or an undirected graph. 3. A graph can be added in vertices and edges 4. A vertex of a graph can contain values in theory, the values can be of any type 5. A graph can be displayed by listing all the possible paths, each linking vertices 6. A graph can be queried by given a starting vertex, listing the path this vertex leads. 7. A graph can be queried by given an edge, if this edge exists in the graph 8. A graph can be queried if a value is contained by any of its vertex.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stduio.h>

#include<stdlib.h>

void main()

{

int option;

do

{

printf("\n A Program to repersent a Graph by using an");

printf("Adjacency Matrix method \n");

printf("\n 1.Directed Graph");

printf("\n 2.Un-Directed Graph ");

printf("\n 3.Exit");

printf("\n\n Select a proper option:");

scanf("%d",&option);

switch(option)

{

case 1:dir_graph():

break;

case 2:undir_graph();

break;

case 3:exit(0);

}

}

while(1);

}

int dir_graph()

{

int adj_mat[50][50];

int n;

int in_deg,out_deg, i, j;

printf("\n How Many vertices ?:");

scanf("%d",&n);

printf("\n vertex \t In Degree \t Out_Degree \t Total_Degree ");

for(i=1; i<n; i++)

{

in_deg = out_deg = 0;

for(j = 1; j<=n; j++)

{

if(adj_mat[j][i]==1)

in_deg++;

}

for(j=1; j<=n; j++)

if(adj_mat[i][j]==1)

out_deg++;

printf("\n\n %5\t\t\t%d\t\t%d\t\t%d\n\n", i, in_deg, out_deg, in_deg +out_deg);

}

return;

}

int undir_graph()

{

int adj_mat[50][50];

int deg,i,j,n;

printf("\n How many vertices");

scanf("%d",&n);

read_graph(adj_mat,n);

printf("n vertex \t Degre");

for (i=1; i<=n; i++)

{

deg=0;

for(j=1; j<=n; j++)

if(adj_mat[i][j]==1)

deg++;

printf("\n\n%5d \t\t %d\n\n", i, deg);

}

return;

}

int read_graph(int adj_mat[50][50], int n)

{

int i, j;

char reply;

for (i=1;i<n;i++)

{

for(j=1;j<=n;j++)

{

if(i==j)

{

adj_mat[i][j]=0;

continue;

}

printf("\n Vertices %d & %d are Adjacent" i,j);

scanf("%c",&reply);

if(reply=='y'|| reply == 'Y')

adj_mat[i][j]=1;

else

adj_mat[i][j]=0;

}

}

retrurn;

}

Add a comment
Know the answer?
Add Answer to:
This project requires you to develop object oriented programs of a graph that can achieve the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write down true (T) or false (F) for each statement. Statements are shown below If a...

    Write down true (T) or false (F) for each statement. Statements are shown below If a graph with n vertices is connected, then it must have at least n − 1 edges. If a graph with n vertices has at least n − 1 edges, then it must be connected. If a simple undirected graph with n vertices has at least n edges, then it must contain a cycle. If a graph with n vertices contain a cycle, then it...

  • Say that we have an undirected graph G(V, E) and a pair of vertices s, t and a vertex v that we call a a desired middle vertex . We wish to find out if there exists a simple path (every vertex appears...

    Say that we have an undirected graph G(V, E) and a pair of vertices s, t and a vertex v that we call a a desired middle vertex . We wish to find out if there exists a simple path (every vertex appears at most once) from s to t that goes via v. Create a flow network by making v a source. Add a new vertex Z as a sink. Join s, t with two directed edges of capacity...

  • Viterbi algorithm We can use dynamic programming on a directed graph G = (V, E) for...

    Viterbi algorithm We can use dynamic programming on a directed graph G = (V, E) for speech recognition. Each edge (u, v) in E is labeled with a sound s(u, v) from a finite set S of sounds. The labeled graph is a formal model of a person speaking a restricted language. Each path in the graph starting from a distinguished vertex v0 in V corresponds to a possible sequence of sounds produced by the model. The label of a...

  • 1. In the following graph, suppose that the vertices A, B, C, D, E, and F represent towns, and th...

    question 1 and 2 please, thank you. 1. In the following graph, suppose that the vertices A, B, C, D, E, and F represent towns, and the edges between those vertices represent roads. And suppose that you want to start traveling from town A, pass through each town exactly once, and then end at town F. List all the different paths that you could take Hin: For instance, one of the paths is A, B, C, E, D, F. (These...

  • Note: For the following problems, you can assume that INDEPENDENT SET, VERTEX COVER, 3-SAT, HAMILTONIAN PATH, and GRAPH COLORING are NP-complete. You, of course, may look up the defini- tions of the...

    Note: For the following problems, you can assume that INDEPENDENT SET, VERTEX COVER, 3-SAT, HAMILTONIAN PATH, and GRAPH COLORING are NP-complete. You, of course, may look up the defini- tions of the above problems online. 5. The LONGEST PATH problem asks, given an undirected graph G (V, E), and a positive integer k , does G contain a simple path (a path visiting no vertex more than once) with k or more edges? Prove that LONGEST PATH is NP-complete. Note:...

  • Please try your best to complete this 11 methods under. I have provided the UndirectedGraph class...

    Please try your best to complete this 11 methods under. I have provided the UndirectedGraph class with the single instance data variable. Do not add any additional instance data variables. Do not modify any other classes provided. In addition to writing the 8 required methods of the interface and the constructor, you will also write methods for the two traversals and an isConnected method. import java.util.Queue; public class UndirectedGraph<T> implements BasicGraphInterface <T> {       private DirectedGraph digraph;      ...

  • hello there ,, can anyone give the solution of this Assuming a graph is represented as...

    hello there ,, can anyone give the solution of this Assuming a graph is represented as an adjacency matrix, write the pseudocode for an algorithm that can determine if any path exists between two vertices. The algorithm would accept as input: The nxn adjacency matrix for an undirected, unweighted graph A source vertex A destination vertex Returning as output: A boolean value indicating whether there is a path between the source and destination. You can use anything for variable/function names...

  • Draw a graph that models the connecting relationships in the floorplan below. The vertices represent the...

    Draw a graph that models the connecting relationships in the floorplan below. The vertices represent the rooms and the edges represent doorways connecting rooms. Vertex F represents the outdoors. Determine whether the graph contains an Euler path or an Euler circuit. If either an Euler path or an Euler circuit exists, find one. B D The graph contains at least one Euler path, but no Euler circuit. An Euler path is DEFBFACFE. The graph contains at least one Euler circuit...

  • hello there ,, can anyone give the solution of this Assuming a graph is represented as an adjacency matrix, write the ps...

    hello there ,, can anyone give the solution of this Assuming a graph is represented as an adjacency matrix, write the pseudocode for an algorithm that can determine if any path exists between two vertices. The algorithm would accept as input: The nxn adjacency matrix for an undirected, unweighted graph A source vertex A destination vertex Returning as output: A boolean value indicating whether there is a path between the source and destination. You can use anything for variable/function names...

  • Reachability. You are given a connected undirected graph G = (V, E ) as an adjacency...

    Reachability. You are given a connected undirected graph G = (V, E ) as an adjacency list. The graph G might not be connected. You want to fill-in a two-dimensional array R[,] so that R[u,v] is 1 if there is a path from vertex u to vertex v. If no such path exists, then R[u,v] is 0. From this two-dimensional array, you can determine whether vertex u is reachable from vertex v in O(1) time for any pair of vertices...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT