如何在有向图中找到最小的顶点集,以便可以到达所有其他顶点

编程入门 行业动态 更新时间:2024-10-12 01:32:27
本文介绍了如何在有向图中找到最小的顶点集,以便可以到达所有其他顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

给出一个有向图,我需要找到所有其他顶点都可以达到的最小顶点集.

Given a directed graph, I need to find the minimum set of vertices from which all other vertices can be reached.

因此,函数的结果应该是最小数量的顶点,通过遵循有向边可以从中获得所有其他顶点.

So the result of the function should be the smallest number of vertices, from which all other vertices can be reached by following the directed edges.

可能的最大结果是没有边缘,因此将返回所有节点.

The largest result possible would be if there were no edges, so all nodes would be returned.

如果图形中有周期,则为每个周期选择一个节点.哪一个无关紧要,但是如果再次运行该算法,则应该保持一致.

If there are cycles in the graph, for each cycle, one node is selected. It does not matter which one, but it should be consistent if the algorithm is run again.

我不确定是否存在现有的算法吗?如果有,它有名字吗?我已经尝试进行研究,最近的事情似乎是找到了母顶点如果是那样的算法,那么可以详细说明实际的算法,因为该链接中给出的答案有点含糊.

I am not sure that there is an existing algorithm for this? If so does it have a name? I have tried doing my research and the closest thing seems to be finding a mother vertex If it is that algorithm, could the actual algorithm be elaborated as the answer given in that link is kind of vague.

鉴于我必须在javascript中实现此功能,因此首选项将是.js库或javascript示例代码.

Given I have to implement this in javascript, the preference would be a .js library or javascript example code.

推荐答案

据我了解,这只是在图中找到强连接的组件. Kosaraju的算法是最简单的方法之一.它使用两次深度优先搜索,而不是后来的仅使用一次深度搜索的算法,但是我最喜欢它的简单概念.

From my understanding, this is just finding the strongly connected components in a graph. Kosaraju's algorithm is one of the neatest approaches to do this. It uses two depth first searches as against some later algorithms that use just one, but I like it the most for its simple concept.

对此进行扩展,找到了最小的一组顶点,正如对这篇文章的评论中所建议的那样:1.找到图的强连接组件-将每个组件简化为单个顶点.2.其余图是DAG(如果存在断开连接的组件,则为DAG组),其根形成所需的顶点组.

Just to expand on that, the minimum set of vertices is found as was suggested in the comments to this post : 1. Find the strongly connected components of the graph - reduce each component to a single vertex. 2. The remaining graph is a DAG (or set of DAGs if there were disconnected components), the root(s) of which form the required set of vertices.

更多推荐

如何在有向图中找到最小的顶点集,以便可以到达所有其他顶点

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

发布评论

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

>www.elefans.com

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