I have a tuple like (1,2),(3,4),(4,5)
. Edges: 1->2
, 3->4
and so on.
How calculate in degree and out degree for each vertex?
I have a tuple like (1,2),(3,4),(4,5)
. Edges: 1->2
, 3->4
and so on.
How calculate in degree and out degree for each vertex?
you can write a function take in a list of tuples which are the edges.
accumulate another list of tuples or (records), with format of [(node, inDgree, OutDgree),...]
records [{node=int, inDgree=int, outDgree = int},...]
fun degrees ((a,b)::(as,bs)) = ....
The out-degree of vertex v
is the number of pairs (x, y)
where x == v
, since each such pair corresponds to an edge starting at v
. Likewise, the in-degree of v
is the number of pairs (x, y)
where y == v
.
Does that give you enough of the basic idea?