"<small><i>This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges).</i></small>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Determine the height of a tree.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Is this a binary tree?\n",
" * Yes\n",
"* Can we assume we already have a Node class with an insert method?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* 5 -> 1\n",
"* 5, 2, 8, 1, 3 -> 3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_height/height_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# %load test_height.py\n",
"from nose.tools import assert_equal\n",
"\n",
"\n",
"class TestHeight(object):\n",
"\n",
" def test_height(self):\n",
" root = Node(5)\n",
" assert_equal(height(root), 1)\n",
" insert(root, 2)\n",
" insert(root, 8)\n",
" insert(root, 1)\n",
" insert(root, 3)\n",
" assert_equal(height(root), 3)\n",
"\n",
" print('Success: test_height')\n",
"\n",
"\n",
"def main():\n",
" test = TestHeight()\n",
" test.test_height()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_height/height_solution.ipynb) for a discussion on algorithms and code solutions."