C - Degree of a directed unweighted graph

Click For Summary
SUMMARY

The discussion focuses on implementing functions to determine the minimum and maximum degree of a directed unweighted graph represented by an adjacency matrix in C. The key functions are int minDegree(GRAPH*); and int maxDegree(GRAPH*);, which calculate the smallest and largest degree by counting in-degrees and out-degrees for each vertex, with loops counted twice. Additionally, variable argument functions GRAPH *f_min(int n,...); and GRAPH *f_max(int n,...); are proposed to return graphs with the smallest and largest degrees, respectively.

PREREQUISITES
  • C programming language proficiency
  • Understanding of graph theory concepts, specifically directed graphs
  • Familiarity with data structures, particularly structs in C
  • Knowledge of variable argument functions in C
NEXT STEPS
  • Implement the minDegree and maxDegree functions to calculate vertex degrees
  • Explore the use of loops in adjacency matrices and their impact on degree calculations
  • Research variable argument functions in C for dynamic graph handling
  • Practice creating and manipulating adjacency matrices for various graph configurations
USEFUL FOR

Students and developers working on graph algorithms, particularly those studying data structures and algorithms in C programming. This discussion is beneficial for anyone needing to implement graph degree calculations efficiently.

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.
 

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
6K
  • · 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