[Math] How to compute the average weight of an undirected graph

graph theory

Given a weighted, undirected graph $G = (V,E)$, how can I compute the average weight of edges?
It seems an easy problem (divide the total weight to the number of edges!) but I couldn't manage to find the sum of the edge weights since each edge can be counted several times while iterating through the vertices.

Best Answer

When you iterate over the vertices you will count every edge $e=\{v,w\}$ exactly twice (once when you visit $v$ and once when you visit $w$).

Thus you can sum up all weights of incident edges for every vertex and divide the result by $2\cdot m$ (where m is the amount of edges) to get the average weight.