public static int degree(Graph G, int v) { int degree = 0; foreach (int w in G.adj(v)) { degree++; } return(degree); }
private void dfs(Graph G, int v) { mark[v] = true; foreach (int w in G.adj(v)) { if (!mark[w]) { edgeTo[w] = v; dfs(G, w); } } }
public static int numberOfSelfLoops(Graph G) { int count = 0; for (int i = 0; i < G.v(); i++) { foreach (int j in G.adj(i)) { if (i == j) { count++; } } } return(count / 2); }
private void bfs(Graph G, int s) { Queue <int> q = new Queue <int>(); mark[s] = true; q.enqueue(s); while (!q.isEmpty()) { int v = q.dequeue(); foreach (int w in G.adj(v)) { if (!mark[w]) { edgeTo[w] = v; mark[w] = true; q.enqueue(w); } } } }