检查关系传递性的算法?
我需要检查关系是否具有传递性?
您能建议一些算法来检查关系的传递性吗?
我将关系存储为布尔矩阵,如果元素与图表中的0相关,则有1。
谢谢。
I need to check if relation is transitive or not?
Would you please suggest some algorithm to check the transitivity of relations?
I am storing relation as a boolean matrix there is 1 if elements are related other wise 0 like in graphs.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
拓扑排序或许是正确的方向。 如果有向图表示中没有循环,则该关系是传递的。 如果您关心速度,图算法可能是最佳选择。
Topological sorting may be the right direction. The relationship is transitive if there are no loops in its directed graph representation. If you care about speed, graph algorithms are probably the way to go.
尽管这听起来完全像家庭作业...
您需要存储您的关系,以便您可以通过先行词快速查找它们。 然后你就可以发现A->B->C类型的传递关系,将它们添加到同一个存储中,并继续查找A->B->C->D,等等。 。
Despite this totally sounds like homework...
You'd need to store your relations so that you can look them up by the antecedent very quickly. Then you can discover transitive relations of the type A->B->C, add them to the same storage, and keep going to look up A->B->C->D, etc etc...
与我的地图/集合版本(已删除)相比,算法更简单,现在带有布尔矩阵。 也许这更容易理解,即使你不懂Java?
Much simpler algorithm as my Map/Set version (deleted), now with boolean matrix. Maybe this is easier to understand, even if you don't know Java?