(self, vid, mode=OUT)
return (vids, parents)
Conducts a depth first search (DFS) on the graph.

        @param vid: the root vertex ID
        @param mode: either C{\"in\"} or C{\"out\"} or C{\"all\"}, ignored
          for undirected graphs.
        @return: a tuple with the following items:
           - The vertex IDs visited (in order)
           - The parent of every vertex in the DFS
Conducts a depth first search (DFS) on the graph.
Conducts a depth first search ( DFS ) on the graph .
def dfs(self, vid, mode=OUT):
        """Conducts a depth first search (DFS) on the graph.

        @param vid: the root vertex ID
        @param mode: either C{\"in\"} or C{\"out\"} or C{\"all\"}, ignored
          for undirected graphs.
        @return: a tuple with the following items:
           - The vertex IDs visited (in order)
           - The parent of every vertex in the DFS
        """
        nv = self.vcount()
        added = [False for v in range(nv)]
        stack = []

        # prepare output
        vids = []
        parents = []

        # ok start from vid
        stack.append((vid, self.neighbors(vid, mode=mode)))
        vids.append(vid)
        parents.append(vid)
        added[vid] = True

        # go down the rabbit hole
        while stack:
            vid, neighbors = stack[-1]
            if neighbors:
                # Get next neighbor to visit
                neighbor = neighbors.pop()
                if not added[neighbor]:
                    # Add hanging subtree neighbor
                    stack.append((neighbor, self.neighbors(neighbor, mode=mode)))
                    vids.append(neighbor)
                    parents.append(vid)
                    added[neighbor] = True
            else:
                # No neighbor found, end of subtree
                stack.pop()

        return (vids, parents)
def dfs ( self , vid , mode = OUT ) : nv = self . vcount ( ) added = [ False for v in range ( nv ) ] stack = [ ] # prepare output vids = [ ] parents = [ ] # ok start from vid stack . append ( ( vid , self . neighbors ( vid , mode = mode ) ) ) vids . append ( vid ) parents . append ( vid ) added [ vid ] = True # go down the rabbit hole while stack : vid , neighbors = stack [ - 1 ] if neighbors : # Get next neighbor to visit neighbor = neighbors . pop ( ) if not added [ neighbor ] : # Add hanging subtree neighbor stack . append ( ( neighbor , self . neighbors ( neighbor , mode = mode ) ) ) vids . append ( neighbor ) parents . append ( vid ) added [ neighbor ] = True else : # No neighbor found, end of subtree stack . pop ( ) return ( vids , parents )