With Self-loops and Without Parallel Edges
In this case, each vertex can have an edge to the every other vertex including itself but parallel edges are not allowed. The maximum number of edges E max in such a graph with the V vertices is given by the formula:
E max = V×V
Implementation:
#include <iostream>
using namespace std;
// Function to return the maximum number of directed edges
// if self loops are allowed and parallel edges are not
// allowed
int GFG(int V) { return V * V; }
int main()
{
int V = 5;
int maxEdges = GFG(V);
cout << "Maximum number of edges with self-loops and "
"without parallel edges: "
<< maxEdges << endl;
return 0;
}
public class Main {
// Function to return the maximum number of directed
// edges if self loops are allowed and parallel edges
// are not allowed
public static int GFG(int V) { return V * V; }
public static void main(String[] args)
{
int V = 5;
int maxEdges = GFG(V);
System.out.println(
"Maximum number of edges with self-loops and without parallel edges: "
+ maxEdges);
}
}
// This code is contributed by Prachi.
# Function to return the maximum number of directed edges
# if self loops are allowed and parallel edges are not
# allowed
def GFG(V):
return V * V
if __name__ == "__main__":
V = 5
max_edges = GFG(V)
print("Maximum number of edges with self-loops and without parallel edges:", max_edges)
// Function to return the maximum number of directed edges
// if self loops are allowed and parallel edges are not
// allowed
function maxEdges(V) {
return V * V;
}
// Main function
function main() {
let V = 5;
let maxEdgesValue = maxEdges(V);
console.log("Maximum number of edges with self-loops and without parallel edges: " + maxEdgesValue);
}
// Call the main function
main();
Output
Maximum number of edges with self-loops and without parallel edges: 25
Maximum Number of Edges in a Directed Graph
In a directed graph, edges have a direction associated with them meaning they point from the one vertex to another. The maximum number of edges in the directed graph depends on the number of the vertices and type of graph.