0

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?

GingerPlusPlus
  • 5,336
  • 1
  • 29
  • 52
offeron
  • 157
  • 2
  • 2
  • 10

2 Answers2

0

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)) = ....
Jesse Zhuang
  • 388
  • 1
  • 4
  • 14
  • Thanks for the reply but am not clear. I have List of tuples like [(1,2),(2,3),(3,4)]. I removed the tuple format and converted as list format like [1,2,2,3,3,4]. Now i need to calculate in degree and out degree for each vertex i.e; 1,2,3,4. – offeron Oct 24 '14 at 19:12
  • you actually do not need to convert the tuples to a list. In the function body you can process the tuples one by one. For a tuple (s,d), write a helper function to check whether it is already in your result list, if in, increment the outdegree by one, if not, create a new entry in your result list with the outdegree to be one. – Jesse Zhuang Oct 25 '14 at 23:06
0

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?

Cactus
  • 27,075
  • 9
  • 69
  • 149