← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 3649.c.3.a

沿BFS父指针打印最短路

理解等级:中级

完成 BFS 后,从目标 v 沿 π 父指针递归回到源点,再按返回顺序输出各点,就得到一条最短边数路径。

若父指针为空且 v 不是源点,应报告不可达;输出成本与路径顶点数成正比。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 第20章 基本图算法 · 查看原书依据

      The PRINT-PATH procedure prints out the vertices on a shortest path from s to v, assuming that BFS has already computed a breadth-first tree. This procedure runs in time linear in the number of vertices in the path printed, since each recursive call is for a path one vertex shorter.

    参考来源

    - 位置:《算法导论(第4版)》第20章《基本图算法》(OEBPS/chapter020.xhtml,文本字符[25000,30000))。 - 结论依据:原文PRINT-PATH过程包含源点基例、不可达出口及递归父指针,说明线性于输出路径。 - 原始内容:The P RINT -P ATH procedure prints out the vertices on a shortest path from s to v , assuming that BFS has already computed a breadth-first tree. This procedure runs in time linear in the number of vertices in the path printed, since each recursive call is for a path one vertex shorter.