Tweaked utopian tree algorithm discussion, cleared challenge code section.

This commit is contained in:
Donne Martin 2015-07-06 05:45:44 -04:00
parent 3061020cc1
commit d4a2300ea0
2 changed files with 4 additions and 11 deletions

View File

@ -68,7 +68,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": false
}, },
@ -78,15 +78,8 @@
"# cycles = 1, print 2: i = 1: 1 * 2\n", "# cycles = 1, print 2: i = 1: 1 * 2\n",
"# cycles = 4, print 7: i = 1: 1 * 2, i = 2: 2 + 1, i = 3: 3 * 2, i = 4: 6 + 1\n", "# cycles = 4, print 7: i = 1: 1 * 2, i = 2: 2 + 1, i = 3: 3 * 2, i = 4: 6 + 1\n",
"def calc_utopian_tree_height(cycles):\n", "def calc_utopian_tree_height(cycles):\n",
" height = 1\n", " # TODO: Implement me\n",
" if cycles == 0:\n", " pass"
" return height\n",
" for i in xrange(1, cycles+1):\n",
" if i % 2 == 1:\n",
" height *= 2\n",
" else:\n",
" height += 1\n",
" return height"
] ]
}, },
{ {

View File

@ -62,7 +62,7 @@
"* Return height\n", "* Return height\n",
"\n", "\n",
"Complexity:\n", "Complexity:\n",
"* Time: O(n), where n is the number of cycles, for each cycle we perform a calculation\n", "* Time: O(n)\n",
"* Space: O(1)" "* Space: O(1)"
] ]
}, },