C - Degree of a directed unweighted graph

username_unknown
Messages
2
Reaction score
0

Homework Statement


Given the representation of directed unweighted graph:
Code:
typedef struct
{
  int n;//num. of vertices
  void *info[MAX];//information of vertices
  int am[MAX][MAX];//adjacency matrix
}GRAPH;

Write a function
Code:
int minDegree(GRAPH*);
and
Code:
int maxDegree(GRAPH*);
that return the smallest and the largest degree of given graph.
Write a function with variable number of arguments
Code:
GRAPH *f_min(int n,...);
by using the function minDegree() that returns the address of a graph with the smallest degree.
Write a function with variable number of arguments
Code:
GRAPH *f_max(int n,...);
by using the function maxDegree() that returns the address of a graph with the largest degree.
n is the number of input graphs.

2. The attempt at a solution
Maximum (minimum) degree of a directed graph is the total number of in-degree and out-degree edges of a vertex that has the largest (smallest) number of edges, with loops counted twice.

So, the algorithm form finding the minimum and maximum degree of a directed graph is to:
1. for each vertex, count the number of connecting edges, and if an edge is a loop, then multiply by two.
2. return the smallest and the largest count.

Could someone please suggest some code, because I am really stuck in implementation of this program?
 
username_unknown said:

Homework Statement


Given the representation of directed unweighted graph:
Code:
typedef struct
{
  int n;//num. of vertices
  void *info[MAX];//information of vertices
  int am[MAX][MAX];//adjacency matrix
}GRAPH;

Write a function
Code:
int minDegree(GRAPH*);
and
Code:
int maxDegree(GRAPH*);
that return the smallest and the largest degree of given graph.
Write a function with variable number of arguments
Code:
GRAPH *f_min(int n,...);
by using the function minDegree() that returns the address of a graph with the smallest degree.
Write a function with variable number of arguments
Code:
GRAPH *f_max(int n,...);
by using the function maxDegree() that returns the address of a graph with the largest degree.
n is the number of input graphs.

2. The attempt at a solution
Maximum (minimum) degree of a directed graph is the total number of in-degree and out-degree edges of a vertex that has the largest (smallest) number of edges, with loops counted twice.

So, the algorithm form finding the minimum and maximum degree of a directed graph is to:
1. for each vertex, count the number of connecting edges, and if an edge is a loop, then multiply by two.
2. return the smallest and the largest count.

Could someone please suggest some code, because I am really stuck in implementation of this program?
You need to take a stab at it first. You could start by fleshing out your algorithm a bit. A GRAPH structure contains information about the number of vertices, so how might you cycle through the vertices?

For a given vertex, how can you use the adjacency matrix to find out which other vertices are connected to that vertex?

To help you get a handle on this problem, it might be helpful to just make up a graph with, say five or so vertices connected in some way. Write the adjacency matrix for that graph, and go through the process manually of finding the degrees of the various paths.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
4K
  • · Replies 34 ·
2
Replies
34
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K