VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-find-total-number-of-edges-in-a-complete-graph/

⇱ Program to find total number of edges in a Complete Graph - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to find total number of edges in a Complete Graph

Last Updated : 2 Sep, 2022

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. 

Examples

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.

👁 Image

The total number of edges in the above complete graph = 10 = (5)*(5-1)/2.

Implementation:


Output
15

Complexity Analysis:

  • Time Complexity: O(1)
  • Auxiliary Space: O(1)
Comment