Given N number of vertices of a Graph. The task is to find the total number of edges possible in a complete graph of N vertices.
Complete Graph: A Complete Graph is a graph in which every pair of vertices is connected by an edge.
Input : N = 3 Output : Edges = 3 Input : N = 5 Output : Edges = 10
The total number of possible edges in a complete graph of N vertices can be given as,
Total number of edges in a complete graph of N vertices = ( n * ( n – 1 ) ) / 2
Example 1: Below is a complete graph with N = 5 vertices.
The total number of edges in the above complete graph = 10 = (5)*(5-1)/2.
Below is the implementation of the above idea:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Ways to Remove Edges from a Complete Graph to make Odd Edges
- Program to find the diameter, cycles and edges of a Wheel Graph
- Maximum number of edges that N-vertex graph can have such that graph is Triangle free | Mantel's Theorem
- Minimum number of edges between two vertices of a graph using DFS
- Count number of edges in an undirected graph
- Number of Simple Graph with N Vertices and M Edges
- Maximum number of edges in Bipartite graph
- Minimum number of edges between two vertices of a Graph
- Maximum number of edges among all connected components of an undirected graph
- Find weight of MST in a complete graph with edge-weights either 0 or 1
- Maximum number of edges to be added to a tree so that it stays a Bipartite graph
- Program to find the number of region in Planar Graph
- Total number of Spanning Trees in a Graph
- Total number of Spanning trees in a Cycle Graph
- Total number of days taken to complete the task if after certain days one person leaves
- Program to find the time remaining for the day to complete
- Path with minimum XOR sum of edges in a directed graph
- All vertex pairs connected with exactly k edges in a graph
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Shortest path with exactly k edges in a directed and weighted graph | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.