From 618eeedfe361b9d64bca8016163ce1bebf70922c Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Tue, 28 Jun 2016 04:38:02 -0400 Subject: [PATCH] Polish graph path exists challenge and solution (#89) Update constraints and code. --- .../path_exists_challenge.ipynb | 14 +++++++++----- .../graph_path_exists/path_exists_solution.ipynb | 16 +++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/graphs_trees/graph_path_exists/path_exists_challenge.ipynb b/graphs_trees/graph_path_exists/path_exists_challenge.ipynb index 95d1250..cc21f3f 100644 --- a/graphs_trees/graph_path_exists/path_exists_challenge.ipynb +++ b/graphs_trees/graph_path_exists/path_exists_challenge.ipynb @@ -37,6 +37,10 @@ "* Is the graph directed?\n", " * Yes\n", "* Can we assume we already have Graph and Node classes?\n", + " * Yes\n", + "* Can we assume the inputs are valid?\n", + " * Yes\n", + "* Can we assume this fits memory?\n", " * Yes" ] }, @@ -177,21 +181,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" + "pygments_lexer": "ipython3", + "version": "3.5.0" } }, "nbformat": 4, diff --git a/graphs_trees/graph_path_exists/path_exists_solution.ipynb b/graphs_trees/graph_path_exists/path_exists_solution.ipynb index 378d046..a37d4b7 100644 --- a/graphs_trees/graph_path_exists/path_exists_solution.ipynb +++ b/graphs_trees/graph_path_exists/path_exists_solution.ipynb @@ -36,6 +36,10 @@ "* Is the graph directed?\n", " * Yes\n", "* Can we assume we already have Graph and Node classes?\n", + " * Yes\n", + "* Can we assume the inputs are valid?\n", + " * Yes\n", + "* Can we assume this fits memory?\n", " * Yes" ] }, @@ -130,8 +134,6 @@ " start.visit_state = State.visited\n", " while queue:\n", " node = queue.popleft()\n", - " if node is None:\n", - " continue\n", " if node is end:\n", " return True\n", " for adj_node in node.adjacent:\n", @@ -222,21 +224,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" + "pygments_lexer": "ipython3", + "version": "3.5.0" } }, "nbformat": 4,