      "collapsed": false
     },
     "outputs": [],
     "source": [
      "def dfs(root, visit_func):\n",
      "    if root is None:\n",
      "        return\n",
      "    visit_func(root)\n",
      "    root.visit_state = State.visited\n",
      "    for node in root.adjacent:\n",
      "        if node.visit_state == State.unvisited:\n",
      "            dfs(node, visit_func)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
 
</s> remove     "def dfs(root, visit_func):\n",
    "    # TODO: Implement me\n",
    "    pass"
 </s> add     "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        # TODO: Implement me\n",
    "        pass" </s> remove     "        graph = Graph()\n",
 </s> add     "        graph = GraphDfs()\n", </s> remove     "        graph = Graph()\n",
 </s> add     "        graph = GraphDfs()\n", </s> remove     "        dfs(nodes[0], self.results.add_result)\n",
 </s> add     "        graph.dfs(nodes[0], self.results.add_result)\n", </s> remove     "        dfs(nodes[0], self.results.add_result)\n",
 </s> add     "        graph.dfs(nodes[0], self.results.add_result)\n",
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
      "collapsed": false
     },
     "outputs": [],
     "source": [
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
    "class GraphDfs(Graph):\n",
    "\n",
    "    def dfs(self, root, visit_func):\n",
    "        if root is None:\n",
    "            return\n",
    "        visit_func(root)\n",
    "        root.visit_state = State.visited\n",
    "        for node in root.adj_nodes.values():\n",
    "            if node.visit_state == State.unvisited:\n",
    "                self.dfs(node, visit_func)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
 Move graph dfs to a class 
graphs_trees/graph_dfs/dfs_solution.ipynb