C - Degree of a directed unweighted graph

In summary: Once you can do that, then you can start thinking about how to code it.In summary, the problem at hand involves finding the minimum and maximum degree of a directed graph, with loops counted twice. The algorithm for this involves cycling through the vertices and counting the number of connecting edges, with the adjacency matrix being a helpful tool for identifying the connected vertices. It may be helpful to practice manually solving this problem on a small graph before attempting to code it.
  • #1
username_unknown
2
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
  • #2
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.
 

Related to C - Degree of a directed unweighted graph

1. What is the definition of C - Degree of a directed unweighted graph?

The C - Degree of a directed unweighted graph is the number of incoming and outgoing edges for each vertex in the graph. It represents the connectivity of a vertex to other vertices in the graph.

2. How is the C - Degree calculated for a directed unweighted graph?

To calculate the C - Degree of a directed unweighted graph, we count the total number of incoming and outgoing edges for each vertex in the graph. This number represents the C - Degree for that particular vertex.

3. What is the significance of the C - Degree in a directed unweighted graph?

The C - Degree is significant because it helps us understand the connectivity of a vertex in a directed unweighted graph. It also helps us analyze the flow of information or relationships between different vertices in the graph.

4. How does the C - Degree differ from the degree of a undirected graph?

The C - Degree differs from the degree of a undirected graph in that the C - Degree considers both incoming and outgoing edges for a vertex, while the degree of an undirected graph only considers the total number of edges connected to a vertex regardless of direction.

5. Can the C - Degree of a directed unweighted graph be negative?

No, the C - Degree of a directed unweighted graph cannot be negative. This is because the C - Degree represents the number of incoming and outgoing edges for a vertex, and the number of edges cannot be negative.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
1K
Replies
34
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top