Consider a weighted undirected graph with positive edge weights and let (u, v)…

20122012

Consider a weighted undirected graph with positive edge weights and let (u, v) be an edge in the graph. It is known that the shortest path from source vertex s to u has weight 53 and the shortest path from s to v has weight 65. Which statement is always true?

Answer: C. Weight (u, v) ≥ 12Concept — For a fixed source s in a weighted graph, the shortest-path distances obey the triangle inequality: for every edge (x, y) of the graph, d(s, y) ≤…

  1. A.

    Weight (u, v) < 12

  2. B.

    Weight (u, v) = 12

  3. C.

    Weight (u, v) ≥ 12

  4. D.

    Weight (u, v) > 12

Attempted by 169 students.

Show answer & explanation

Correct answer: C

Concept — For a fixed source s in a weighted graph, the shortest-path distances obey the triangle inequality: for every edge (x, y) of the graph, d(s, y) ≤ d(s, x) + w(x, y). The reason is that walking a shortest path to x and then crossing that edge is itself one particular s-to-y route, and no route can be shorter than the shortest one. Since the graph here is undirected, the same bound also holds with the two endpoints exchanged.

Application — Apply the inequality to the edge (u, v), treating v as the far endpoint:

  1. Write the triangle inequality for this edge: d(s, v) ≤ d(s, u) + w(u, v).

  2. Substitute the two distances given in the stem: 65 ≤ 53 + w(u, v).

  3. Subtract 53 from both sides: w(u, v) ≥ 12.

Cross-check — Taking the edge the other way round gives d(s, u) ≤ d(s, v) + w(u, v), that is 53 ≤ 65 + w(u, v), which every positive weight already satisfies, so it adds nothing new. So w(u, v) ≥ 12 is the full strength of what the given distances force. The value 12 is genuinely reachable: build the graph s–u of weight 53 and u–v of weight 12, with no cheaper route to v. Then d(s, u) = 53 and d(s, v) = 65 exactly as stated, and the edge weighs precisely 12. Conversely, if a separate s-to-v route of length 65 already exists, the edge (u, v) may be raised to weight 100 without changing either distance, so the weight is not pinned to one value either.

Contrast — Testing each candidate statement against those two graphs:

Statement about w(u, v)

True in every graph fitting the data?

Reason

w(u, v) < 12

No

It contradicts 65 ≤ 53 + w(u, v), so no graph fitting the stem allows it.

w(u, v) = 12

No

The graph with the 100-weight edge keeps both distances and breaks the equality.

w(u, v) > 12

No

The graph with the 12-weight edge keeps both distances and breaks the strictness.

w(u, v) ≥ 12

Yes

It is exactly the bound the triangle inequality forces, and both graphs respect it.

Hence the statement that is always true is w(u, v) ≥ 12. In algorithmic terms this is the same fact edge relaxation relies on: once every distance is final, no edge can still relax, so d(s, v) ≤ d(s, u) + w(u, v) must already hold, with equality exactly when the edge lies on a shortest path to v.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Coding For Placement

Loading lesson…