mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-06 17:38:02 +00:00
Polish bst successor challenge and solution (#82)
Update constraints, test cases, tests, algorithm discussion, and code.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user