function to compute degree of a vertex.