Question: Let G be a weighted undirected connected graph. Write, in pseudo-code, an algorithm sumCrossEdges(G) that performs DFS of G and returns the sum of weights
Let G be a weighted undirected connected graph. Write, in pseudo-code, an algorithm sumCrossEdges(G) that performs DFS of G and returns the sum of weights of edges that get labeled as 'cross' edges.
Answer in pseudo-code that resembles the below example for a BFS on the same question.

Algorithm sumCrossEdges (G) sum = 0 for e E G.edges(0) mark e unvisited for v E G.vertices() mark v unvisited s - G.vertices().getFirst() Q new empty sequence Q.insertlast(s) mark s visited while Q is not empty u = Q.first() for all e E G.incidentEdges(v) do w opposite(v, e) if w is not visited mark ww set label of e to DISCOVERY Q.insertLast (w) else if e is not visited set label of e to CROSS sum sume.getWeightO return sum
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
