data_structures/graphs/searches.py
def dfs_rec_list(g, s):
    """
    Recursive Depth First Search for adjacency lists

    :param g: the graph to visit. It is assumed the list only contains int data type.
    :type g: list(list(int))
    :param s: the vertex to start from.
    :type s: int
    :return: list of visited vertices
    """
    
    def visit(v):
        visited_vertices.append(v)
        for u in g[v]:
            if u not in visited_vertices:
                visit(u)
    
    visited_vertices = []
    visit(s)
    return visited_vertices

    Recursive Depth First Search for adjacency lists

    :param g: the graph to visit. It is assumed the list only contains int data type.
    :type g: list(list(int))
    :param s: the vertex to start from.
    :type s: int
    :return: list of visited vertices
    
Recursive Depth First Search for adjacency lists
Recursive Depth First Search for adjacency lists
def dfs_rec_list(g, s):
    def visit(v):
        visited_vertices.append(v)
        for u in g[v]:
            if u not in visited_vertices:
                visit(u)
    visited_vertices = []
    visit(s)
    return visited_vertices
def dfs_rec_list ( g , s ) : def visit ( v ) : visited_vertices . append ( v ) for u in g [ v ] : if u not in visited_vertices : visit ( u ) visited_vertices = [ ] visit ( s ) return visited_vertices
Recursive Depth First Search for adjacency lists
Recursive Depth First Search for adjacency lists
"""
    Recursive Depth First Search for adjacency lists

    :param g: the graph to visit. It is assumed the list only contains int data type.
    :type g: list(list(int))
    :param s: the vertex to start from.
    :type s: int
    :return: list of visited vertices
    """
list of visited vertices
list of visited vertices
g
the graph to visit. It is assumed the list only contains int data type.
the graph to visit . It is assumed the list only contains int data type .
s
the vertex to start from.
the vertex to start from .