使用Dijkstra's在加权有向图中找到最低权重周期

编程入门 行业动态 更新时间:2024-10-21 03:41:52
本文介绍了使用Dijkstra's在加权有向图中找到最低权重周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在为这个问题而苦苦挣扎。如下所示:

Hi I am struggling with this question. It is the following:

设计一种算法,以找到权重最低的循环(即图中所有循环,其中一个具有加权有向图G =(V,E)中最小的边缘权重之和)。简要说明运行时间和空间复杂性。假设所有边都是非负的。它应在O(| V || E | log | V |)时间运行。 提示:使用多次调用Dijkstra的算法。

Devise an algorithm to find the lowest-weight cycle(i.e. of all cycles in the graph, the one with the smallest sum of edge weights), in a weighted, directed graph G = (V,E). Briefly justify the runtime and space complexity. Assume all edges are non-negative. It should run in O(|V||E|log|V|) time. Hint: Use multiple calls to Dijkstra's algorithm.

我见过使用Floyd-Warshall的解决方案,但我想知道如何我们将使用Dijkstra以及如何在给定的时间限制内做到这一点。

I have seen solutions that use Floyd-Warshall but I was wondering how we would do this using Dijkstra's and how to do it within the time constraint given.

我有几点困惑:

  • 首先,我们如何甚至知道图中有多少个周期以及如何检查这些周期?
  • 此外,为什么| E || V | log | V |?据我了解,您应该遍历的所有顶点,因此使其成为| V | log | V |。

这是对于我的个人学习,因此,如果有人有可以使用的示例,那将对我有很大帮助!我并不是真正在寻找伪代码-只是一种通用算法,可以了解如何使用从一个节点到所有节点的最短路径来帮助我们解决此问题。 谢谢!

This is for my personal learning so if anyone has an example they could use, it would greatly help me! I am not really looking for pseudo-code - just a general algorithm to understand how using the shortest path from one node to all nodes is going to help us solve this problem. Thank you!

推荐答案

从每个顶点调用Dijkstra的算法,以找到到自身的最短路径(如果存在)。从任何顶点到其自身的最短路径是最小周期。 Dijkstra的算法取O(| E | log | V |),所以总时间为O(| V || E | log | V |)。

Call Dijkstra's algorithm from each vertex to find the shortest path to itself, if one exists. The shortest path from any vertex to itself is the smallest cycle. Dijkstra's algorithm takes O(|E| log |V|), so total time is O(|V||E| log |V|).

请注意,这次可能比Floyd-Warshall还要糟糕,因为图中可能有O(| V | ^ 2)条边。

Note that this time can be worse than Floyd-Warshall, because there can be O(|V|^2) edges in the graph.

更多推荐

使用Dijkstra's在加权有向图中找到最低权重周期

本文发布于:2023-11-29 20:31:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647550.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:权重   图中   周期   最低   Dijkstra

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!