Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions