Program to count the number of edges in an undirected graph | faceprep

Program to count the number of edges in an undirected graph | faceprep

The program to count the number of edges in an undirected graph is discussed here.

Given an adjacency list representation of an undirected graph, the task is to find the number of edges in it.

Count number of edges in an undirected graph


Algorithm to count the number of edges in an undirected graph

  • Input the adjacency list representation of an undirected graph.
  • In every finite undirected graph, the number of vertices with an odd degree is always even.
  • The handshaking lemma is a consequence of the degree sum formula,sum _{vin V}deg(v)=2|E|,.
  • So we traverse all vertices, compute the sum of sizes of their adjacency lists, and finally return sum/2.


face prep pro ad bannerClick here to learn more about FACE Prep PRO


Program to count the number of edges in an undirected graph

@@coding::1@@


Recommended Programs


Count number of edges in an undirected graph