It uses the opposite strategy as depth-first search, which instead explores the highest-depth nodes first before being forced to backtrack回溯 and expand shallower nodes. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key'), and explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level. it delays checking whether a vertex has been discovered until the vertex is popped from the stack rather than making this check before adding the vertex.īreadth-first search ( BFS) is an algorithm for traversing or searching tree or graph data structures.it uses a stack instead of a queue, and.The non-recursive implementation is similar to breadth-first search but differs from it in two ways: The non-recursive implementation will visit the nodes as: A, E, F, B, D, C, G. The recursive implementation will visit the nodes from the example graph in the following order: A, B, D, F, E, C, G. These two variations of DFS visit the neighbors of each vertex in the opposite order from each other: the first neighbor of v visited by the recursive variation is the first one in the list of adjacent edges, while in the iterative variation the first visited neighbor is the last one in the list of adjacent edges. A non-recursive implementation of DFS with worst-case space complexity O(|E|):(使用栈,先进后出) 1 procedure DFS-iterative( G, v):Ĩ for all edges from v to w in G.adjacentEdges( v) do The order in which the vertices are discovered by this algorithm is called the lexicographic order. Output: All vertices reachable from v labeled as discovered A recursive implementation of DFS: 1 procedure DFS( G, v):ģ for all edges from v to w in G.adjacentEdges( v) doĤ if vertex w is not labeled as discovered then Iterative deepening is one technique to avoid this infinite loop and would reach all nodes. forever, caught in the A, B, D, F, E cycle and never reaching C or G. Performing the same search without remembering previously visited nodes results in visiting nodes in the order A, B, D, F, E, A, B, D, F, E, etc. The edges traversed in this search form a Trémaux tree, a structure with important applications in graph theory. Will visit the nodes in the following order: A, B, D, F, E, C, G. " Else ProcessFolder mdl End If Private sub ProcessFolder(folder) On Error Resume Next Dim Tab 'running table for each Tab in folder.tables if not tab.isShortcut then tab.name = tab.comment Dim col ' running column for each col in tab.columns if col.comment="" then else col.name= col.comment end if next end if next Dim view 'running view for each view in folder.Views if not view.isShortcut then view.name = ment end if next ' go into the sub-packages Dim f ' running folder For Each f In folder.Packages if not f.The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking 回溯.Īssuming that the left edges in the shown graph are chosen before right edges,Īnd assuming the search remembers previously visited nodes and will not repeat them (since this is a small graph), Option Explicit ValidationMode = True InteractiveMode = im_Batch Dim mdl ' the current model ' get the current active model Set mdl = ActiveModel If (mdl Is Nothing) Then MsgBox "There is no current Model " ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then MsgBox "The current model is not an Physical Data model. 3、tools > execute command > edit/Run Script