Skip to content
Official PYQ · 2021

GATE CS 2021 Set 2 Q55 — Graph Traversals (BFS, DFS)

Explain with AI

In a directed acyclic graph with a source vertex s\textsf{s}, the quality-score\textit{quality-score} of a directed path is defined to be the product of the weights of the edges on the path. Further, for a vertex vv other than s\textsf{s}, the quality-score of vv is defined to be the maximum among the quality-scores of all the paths from s\textsf{s} to vv. The quality-score of s\textsf{s} is assumed to be 11.

The sum of the quality-scores of all vertices on the graph shown above is _______

View worked solution

Answer: 929 : 929

The quality-score Q(v)Q(v) of any vertex vv (other than the source ss) is the maximum of the quality-scores of all paths from ss to vv. This can be computed dynamically using the relation:

Q(v)=max⁡(u,v)∈E{Q(u)×w(u,v)}Q(v) = \max_{(u, v) \in E} \left\{ Q(u) \times w(u, v) \right\}

With Q(s)=1Q(s) = 1, we compute the quality-scores of the vertices in topological order:

  • Vertex aa: Q(a)=Q(s)×9=9Q(a) = Q(s) \times 9 = 9
  • Vertex bb: Q(b)=Q(s)×9=9Q(b) = Q(s) \times 9 = 9
  • Vertex ff: Q(f)=Q(s)×10=10Q(f) = Q(s) \times 10 = 10
  • Vertex cc: Q(c)=max⁡(Q(a)×10, Q(b)×9)=max⁡(90,81)=90Q(c) = \max(Q(a) \times 10, \, Q(b) \times 9) = \max(90, 81) = 90
  • Vertex dd: Q(d)=Q(b)×9=81Q(d) = Q(b) \times 9 = 81
  • Vertex ee: Q(e)=max⁡(Q(c)×8, Q(d)×9)=max⁡(720,729)=729Q(e) = \max(Q(c) \times 8, \, Q(d) \times 9) = \max(720, 729) = 729

Summing the quality-scores of all vertices:

Total Sum=Q(s)+Q(a)+Q(b)+Q(c)+Q(d)+Q(e)+Q(f)\text{Total Sum} = Q(s) + Q(a) + Q(b) + Q(c) + Q(d) + Q(e) + Q(f) Total Sum=1+9+9+90+81+729+10=929\text{Total Sum} = 1 + 9 + 9 + 90 + 81 + 729 + 10 = 929

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Graph Traversals (BFS, DFS) questions