Search code examples
algorithmbreadth-first-search

Confusion in Proof for Breadth First Search Finding Shortest Path in CLRS


I am reading CLRS (https://pd.daffodilvarsity.edu.bd/course/material/book-430/pdf_content), and stuck on the proof of Theorem 22.5 - Correctness of Breadth First Search on Page 600.

The author is trying to prove that for every vertex 𝑣 reachable from source 𝑠 in the graph, BFS sets 𝑣.𝑑 = δ(𝑠, 𝑣), where 𝑣.𝑑 is the shortest distance found by BFS for 𝑣 and δ(𝑠, 𝑣) is the shortest distance from 𝑠 to 𝑣. But a step in the proof assumes the above property to be true for some neighbor vertex 𝑢 of 𝑣, giving the reason as "because of how we chose 𝑣":

enter image description here

I'm sure that I am missing something here.

What is special in the way that 𝑣 is chosen that allows us to assume the above mentioned property for some neighbor 𝑢 of 𝑣?


Solution

  • But a step in the proof assumes the above property to be true for some neighbor vertex u of v

    Not just some neighbor of 𝑣, but a neighbor that precedes 𝑣 on the breadth-first path to it. Quoting the text:

    Let 𝑢 be the vertex immediately preceding 𝑣 on a shortest path from 𝑠 to 𝑣, so that δ(𝑠,𝑣) = δ(𝑠,𝑢) + 1. Because δ(𝑠,𝑢) < δ(𝑠,𝑣), and because of how we chose 𝑣, we have 𝑢.𝑑 = δ(𝑠,𝑢).

    "how we chose 𝑣" refers to the following:

    Let 𝑣 be the vertex with minimum δ(𝑠,𝑣) that receives such an incorrect 𝑑 value;

    The key word here is "minimum". This means that 𝑢, which is closer to 𝑠 than 𝑣 is, cannot have an incorrect 𝑑, otherwise 𝑣 wasn't the minimum one. So we trust 𝑢.𝑑 to be δ(𝑠,𝑢).