Polish tree dfs challenge and solution (#78)

Update constraints and algorithm discussion.
This commit is contained in:
Donne Martin 2016-06-25 08:30:02 -04:00 committed by GitHub
parent c7854b69cc
commit 884bbe4870
2 changed files with 21 additions and 18 deletions

View File

@ -18,7 +18,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement depth-first searches (in-order, pre-order, post-order traversals) on a binary tree.\n",
"## Problem: Implement depth-first traversals (in-order, pre-order, post-order) on a binary tree.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
@ -34,6 +34,10 @@
"## Constraints\n",
"\n",
"* Can we assume we already have a Node class with an insert method?\n",
" * Yes\n",
"* What should we do with each node when we process it?\n",
" * Call an input method `visit_func` on the node\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
@ -203,21 +207,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,

View File

@ -18,7 +18,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement depth-first searches (in-order, pre-order, post-order traversals) on a binary tree.\n",
"## Problem: Implement depth-first traversals (in-order, pre-order, post-order) on a binary tree.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
@ -34,6 +34,10 @@
"## Constraints\n",
"\n",
"* Can we assume we already have a Node class with an insert method?\n",
" * Yes\n",
"* What should we do with each node when we process it?\n",
" * Call an input method `visit_func` on the node\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
@ -67,6 +71,10 @@
"\n",
"## Test Cases\n",
"\n",
"Note:\n",
"\n",
"* This following are all forms of depth-first traversals\n",
"\n",
"### In-Order Traversal\n",
"\n",
"* Recursively call in-order traversal on the left child\n",
@ -77,9 +85,6 @@
"* Time: O(n)\n",
"* Space: O(m), where m is the recursion depth, or O(1) if using an iterative approach\n",
"\n",
"Note:\n",
"* This is a form of a depth-first traversal\n",
"\n",
"### Pre-Order Traversal\n",
"\n",
"* Visit the current node\n",
@ -90,9 +95,6 @@
"* Time: O(n)\n",
"* Space: O(m), where m is the recursion depth, or O(1) if using an iterative approach\n",
"\n",
"Note:\n",
"* This is a form of a depth-first traversal\n",
"\n",
"### Post-Order Traversal\n",
"\n",
"* Recursively call post-order traversal on the left child\n",
@ -101,10 +103,7 @@
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(m), where m is the recursion depth, or O(1) if using an iterative approach\n",
"\n",
"Note:\n",
"* This is a form of a depth-first traversal"
"* Space: O(m), where m is the recursion depth, or O(1) if using an iterative approach"
]
},
{
@ -279,7 +278,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.5.0"
}
},
"nbformat": 4,