[英]Represent graph in table and given visited nodes which nodes to visit next
假設我有一個具有N個節點111,222,...,nnn的圖,並且具有下表中表示的圖,例如
NodeID | PredecessorID
222 111
333 111
555 222
555 333
等等。
給定已訪問的M個節點的列表,我如何找到接下來要訪問的所有節點? 接下來要訪問的節點是其所有先前節點已被訪問的節點。
如果您的列表M包含所有訪問過的節點,而不僅僅是它們的一個子集,您可以這樣做:
foreach n in N:
visite = True
if n is not marked:
foreach predecessor (pn) of n:
visite = visite and (is pn marked)
if visite = True:
add n to visitable nodes
在最壞的情況下predecessors of n
的predecessors of n
為N
(完整圖),因此其運行時復雜度為O(N ^ 2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.