Polish bst successor challenge and solution (#82)

Update constraints, test cases, tests, algorithm discussion, and code.
This commit is contained in:
Donne Martin
2016-06-25 22:06:35 -04:00
committed by GitHub
parent 042161dc3b
commit 7b573ceaa3
3 changed files with 46 additions and 15 deletions

View File

@@ -36,7 +36,11 @@
"\n",
"* If there is no successor, do we return None?\n",
" * Yes\n",
"* If the input is None, should we throw an exception?\n",
" * Yes\n",
"* Can we assume we already have a Node class that keeps track of parents?\n",
" * Yes\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
@@ -57,10 +61,11 @@
" /\n",
" 9\n",
"\n",
"In: 4 Out: 5\n",
"In: 5 Out: 6\n",
"In: 8 Out: 9\n",
"In: 15 Out: None\n",
"In: None Out: Exception\n",
"In: 4 Out: 5\n",
"In: 5 Out: 6\n",
"In: 8 Out: 9\n",
"In: 15 Out: None\n",
"</pre>"
]
},
@@ -129,10 +134,15 @@
"source": [
"# %load test_bst_successor.py\n",
"from nose.tools import assert_equal\n",
"from nose.tools import raises\n",
"\n",
"\n",
"class TestBstSuccessor(object):\n",
"\n",
" @raises(Exception)\n",
" def test_bst_successor_empty(self):\n",
" bst_successor(None)\n",
"\n",
" def test_bst_successor(self):\n",
" nodes = {}\n",
" node = Node(5)\n",
@@ -160,6 +170,7 @@
"def main():\n",
" test = TestBstSuccessor()\n",
" test.test_bst_successor()\n",
" test.test_bst_successor_empty()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
@@ -192,7 +203,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.5.0"
}
},
"nbformat": 4,