C - Degree of a directed unweighted graph

AI Thread Summary
The discussion focuses on implementing functions to find the minimum and maximum degree of a directed unweighted graph represented by an adjacency matrix. The minimum and maximum degree are defined as the smallest and largest total number of in-degree and out-degree edges for any vertex, with loops counted twice. Participants suggest starting with a clear algorithm that involves counting connecting edges for each vertex and utilizing the adjacency matrix for connections. There is a call for code examples to assist in the implementation, emphasizing the need to understand the graph structure and vertex connections. The conversation encourages hands-on practice by creating a sample graph to manually calculate degrees.
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?
 
Physics news on Phys.org
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.
 
Back
Top