From 1321723eb937cca694646108a1eae34e8e202096 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Sat, 25 Jun 2016 08:23:28 -0400 Subject: [PATCH] Polish bst min challenge and solution (#76) Update constraints, algorithm discussion, and code. --- graphs_trees/bst_min/bst_min_challenge.ipynb | 16 +++++++------- graphs_trees/bst_min/bst_min_solution.ipynb | 22 +++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/graphs_trees/bst_min/bst_min_challenge.ipynb b/graphs_trees/bst_min/bst_min_challenge.ipynb index 9ec1945..52e76d5 100644 --- a/graphs_trees/bst_min/bst_min_challenge.ipynb +++ b/graphs_trees/bst_min/bst_min_challenge.ipynb @@ -39,6 +39,8 @@ "* Are the array elements unique?\n", " * Yes\n", "* Can we assume we already have a Node class with an insert method?\n", + " * Yes\n", + "* Can we assume this fits memory?\n", " * Yes" ] }, @@ -90,11 +92,11 @@ "source": [ "def create_min_bst(array):\n", " # TODO: Implement me\n", - " # Calls __create_min_bst__\n", + " # Calls _create_min_bst\n", " pass \n", "\n", "\n", - "def __create_min_bst__(array, start, end):\n", + "def _create_min_bst(array, start, end):\n", " # TODO: Implement me\n", " pass" ] @@ -171,21 +173,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/bst_min/bst_min_solution.ipynb b/graphs_trees/bst_min/bst_min_solution.ipynb index 228fe95..b4b97cc 100644 --- a/graphs_trees/bst_min/bst_min_solution.ipynb +++ b/graphs_trees/bst_min/bst_min_solution.ipynb @@ -38,6 +38,8 @@ "* Are the array elements unique?\n", " * Yes\n", "* Can we assume we already have a Node class with an insert method?\n", + " * Yes\n", + "* Can we assume this fits memory?\n", " * Yes" ] }, @@ -103,16 +105,16 @@ "def create_min_bst(array):\n", " if array is None:\n", " return\n", - " return __create_min_bst__(array, 0, len(array)-1)\n", + " return _create_min_bst(array, 0, len(array)-1)\n", "\n", "\n", - "def __create_min_bst__(array, start, end):\n", + "def _create_min_bst(array, start, end):\n", " if end < start:\n", - " return\n", + " return None\n", " mid = (start + end) // 2\n", " node = Node(array[mid])\n", - " node.left = __create_min_bst__(array, start, mid-1)\n", - " node.right = __create_min_bst__(array, mid+1, end)\n", + " node.left = _create_min_bst(array, start, mid-1)\n", + " node.right = _create_min_bst(array, mid+1, end)\n", " return node" ] }, @@ -199,21 +201,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,