简体   繁体   English

使用O(log(N)(N + M)进行图搜索

[英]Graph search with O(log(N)(N+M)

First an explanation: I'm implementing a package manager emulator in java, ie a package manager that just outputs the right things but doesn't actually install anything. 首先说明一下:我正在用Java实现一个程序包管理器仿真器,即一个程序包管理器,它只输出正确的内容,而实际上并没有安装任何东西。 The thing is I need to search through every package and all it's dependencies to see if they are all installed correctly. 关键是我需要搜索每个软件包及其所有依赖项,以查看它们是否都正确安装。 I've been told that it is possible to get worst-case running time equal to log(N)(N+M), where N is amount of packages and M is the amount of dependencies. 有人告诉我,有可能获得等于log(N)(N + M)的最坏情况下的运行时间,其中N是软件包的数量,M是依赖项的数量。 I believe it is some kind of BFS implementation that needs to be done, maybe just do a BFS to each package and it's dependencies, so if I get to a package that has been checked through some other package's dependencies it will just skip over. 我相信这是需要完成的某种BFS实现,也许只是对每个软件包及其依赖项都进行了BFS调整,因此,如果我找到一个已通过其他软件包的相关性检查过的软件包,它将跳过。 This however, in my head, does not seem to have the right worst-case running time. 但是,在我看来,这似乎没有正确的最坏情况下的运行时间。

Does anyone have any idea on how to achieve getting the right running time? 是否有人对如何获得正确的运行时间有任何想法?

I think that this can be done by a topological sort and is often done by piggybacking off of DFS, not BFS. 我认为这可以通过拓扑排序来完成,并且通常可以通过背负DFS(而非BFS)来完成。 That has a linear time of O(M + N). 线性时间为O(M + N)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM