Skip to content

Commit

Permalink
update Ch13
Browse files Browse the repository at this point in the history
  • Loading branch information
rambasnet committed Nov 8, 2023
1 parent f3f04b7 commit a69ba9c
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions Ch13-Recursion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,23 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.03320667683146894"
"0.032029791036620736"
]
},
"execution_count": 10,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# run it \n",
"timeit('factorial(10000)', globals=globals(), number=1)"
"timeit('factorial(10_000)', globals=globals(), number=1)"
]
},
{
Expand Down Expand Up @@ -274,24 +274,24 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.08025467395782471"
"0.07616704609245062"
]
},
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# in fact it takes longer for Python as tail recurion is not optimized\n",
"# stack usage is O(n)\n",
"timeit('factorial_tail(10000, 1)', globals=globals(), number=1)"
"timeit('factorial_tail(10_000, 1)', globals=globals(), number=1)"
]
},
{
Expand All @@ -318,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -335,7 +335,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand All @@ -344,7 +344,7 @@
"2178309"
]
},
"execution_count": 22,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -368,16 +368,16 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.57934181811288"
"0.5792814260348678"
]
},
"execution_count": 20,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -398,7 +398,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -412,22 +412,39 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2178309\n"
]
}
],
"source": [
"print(fib_tail(32, 0, 1))"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.5725738150067627"
"1.3248994946479797e-05"
]
},
"execution_count": 21,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"timeit(\"fib(32)\", globals=globals(), number=1)"
"timeit(\"fib_tail(32, 0, 1)\", globals=globals(), number=1)"
]
},
{
Expand Down

0 comments on commit a69ba9c

Please sign in to comment.