`Computer-Algorithm` 最短路Shortest-Path,Dijkstra,SPFA,Floyd

news/2024/9/19 17:20:30

Contents

  • 最短路Shortest-Path
    • Algorithm: Dijkstra

最短路Shortest-Path

Algorithm: Dijkstra

Given a graph G G G, an total-order ≤ \leq on the set of the weight of all path ∣ A B ∣ |AB| AB (AB can be same) and a binary operator + + +, then the weight of a path (the sum of all edges on the path, denotes ∣ A B ∣ |AB| AB) must satisfying a property (a bit like triangular inequality, but not same):

  • If ∣ A B ∣ ≤ ∣ A C ∣ |AB| \leq |AC| ABAC, then ∣ A B ∣ ≤ ∣ A C ∣ + ∣ C B ∣ |AB| \leq |AC| + |CB| ABAC+CB ( A B C ABC ABC maybe the same)

Then, Dijkstra is used to calculate the least-element under the order ≤ \leq of the weight ∣ S X ∣ |SX| SX where S S S is a start-point, X X X is a any point.

There are some examples:

  • A graph (may contains loop (self-loop or non-self-loop)) with all edges ≥ 0 \geq 0 0, the weight of a path is the sum of all edges on it and given a start-point S S S, calculate the minimal-distance of ∣ S X ∣ |SX| SX (X is an arbitrary point)
    Defining the Dijkstra-Order ≤ ( a , b ) = a ≤ b \leq(a,b) = a \leq b (a,b)=ab, Dijkstra-Add + ( a , b ) = a + b +(a,b) = a + b +(a,b)=a+b
    Then, we can found this satisfies the Dijkstra-Triangular-Inequality

  • A graph (may contains loop (self-loop or non-self-loop)) with all edges ≤ 0 \leq 0 0, the weight of a path is the sum of all edges on it and given a start-point S S S, calculate the maximal-distance of ∣ S X ∣ |SX| SX (X is an arbitrary point)
    Defining the Dijkstra-Order ≤ ( a , b ) = a ≥ b \leq(a,b) = a \geq b (a,b)=ab (notice here), Dijkstra-Add + ( a , b ) = a + b +(a,b) = a + b +(a,b)=a+b
    Then, we can found this satisfies the Dijkstra-Triangular-Inequality

  • A graph (may contains loop (self-loop or non-self-loop)) with all edges be any real-number in [ 0 , 1 ] [0, 1] [0,1], the weight of a path is the product of all edges on it and given a start-point S S S, calculate the maximal-distance of ∣ S X ∣ |SX| SX (X is an arbitrary point)
    Defining the Dijkstra-Order ≤ ( a , b ) = a ≥ b \leq(a,b) = a \geq b (a,b)=ab (notice here), Dijkstra-Add + ( a , b ) = a ∗ b +(a,b) = a * b +(a,b)=ab
    Then, we can found this satisfies the Dijkstra-Triangular-Inequality


http://lihuaxi.xjx100.cn/news/295563.html

相关文章

Rust权威指南之错误处理

一. 简述 在Rust中,我们将错误分为两大类:可恢复错误和不可恢复错误。 可恢复错误:例如文件未找到等,一般需要它们报告给用户并再次尝试进行操作; 不可恢复错误:这类错误往往就是Bug的另一种说法&#xf…

LeetCode 0895. 最大频率栈

【LetMeFly】895.最大频率栈 力扣题目链接:https://leetcode.cn/problems/maximum-frequency-stack/ 设计一个类似堆栈的数据结构,将元素推入堆栈,并从堆栈中弹出出现频率最高的元素。 实现 FreqStack 类: FreqStack() 构造一个空的堆栈。…

20221201今天的世界发生了什么

///亦我123看房COO刘航:中国是全球范围内VR看房普及度最高的国家 中国是全球范围内VR看房普及度最高、应用度最高、效率最高的国家,VR看房已经成为了行业的硬标准 ///快手电商2022年支付GMV将达4100亿 较上一年增长26%。支付GMV只计入所有已支付订单&a…

【python小项目】用python写一个小工具——番茄钟

用python写一个小工具——番茄钟 最近听到朋友说在用番茄钟,有点兴趣也想下载一个来用用,后面仔细一想这玩意做起来也不难,索性自己顺手写一个算了,在这里也分享给大家了 一、功能简述 番茄钟即番茄工作法,番茄工作法…

nvcc编译器之设备和主机独立编译(chapter 6)

目录 6. CUDA中的独立编译 6.1 单独编译时的代码改动 6.2 nvcc独立编译选项 6.3 库 6.4 示例 6.5 分布编译优化 6.6 独立编译的潜在问题 6. CUDA中的独立编译 在5.0版本之前,CUDA不支持分开编译,因此CUDA代码不能访问跨文件(编译单元&…

一起学时序分析之建立/保持时间裕量

何为裕量? 裕量,英文名称叫做“Slack”。我们在Vivado实现后的报告中常常能看到这样一栏: 因为都是缩写,所以我们来解释一下前四栏的含义: WNS,即Worst Negative Slack,最差负时序裕量。这个表…

最全面的Spring教程(五)——文件上传与下载

前言 本文为 【SpringMVC教程】文件上传与下载 相关知识&#xff0c;具体将对使用MultipartResolver处理文件上传的步骤&#xff0c;两种文件下载方式&#xff08;直接向response的输出流中写入对应的文件流、使用 ResponseEntity<byte[]>来向前端返回文件&#xff09;等…

计算机毕业设计Java高校共享单车管理系统(源码+系统+mysql数据库+lw文档)

计算机毕业设计Java高校共享单车管理系统&#xff08;源码系统mysql数据库lw文档&#xff09; 计算机毕业设计Java高校共享单车管理系统&#xff08;源码系统mysql数据库lw文档&#xff09;本源码技术栈&#xff1a; 项目架构&#xff1a;B/S架构 开发语言&#xff1a;Java语…