Skip to content

Commit cf42a33

Browse files
committed
Stack and Fibo added
1 parent 51ac3ad commit cf42a33

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

DP/Fibo.ipynb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"def fib(n, lookup): \n",
10+
" \n",
11+
" # Base case \n",
12+
" if n == 0 or n == 1 : \n",
13+
" lookup[n] = n \n",
14+
" \n",
15+
" # If the value is not calculated previously then calculate it \n",
16+
" if lookup[n] is None: \n",
17+
" lookup[n] = fib(n-1 , lookup) + fib(n-2 , lookup) \n",
18+
" \n",
19+
" # return the value corresponding to that value of n \n",
20+
" return lookup[n] \n",
21+
"# end of function \n",
22+
" \n",
23+
"# Driver program to test the above function \n",
24+
"def main(): \n",
25+
" n = 34 \n",
26+
" # Declaration of lookup table \n",
27+
" # Handles till n = 100 \n",
28+
" lookup = [None]*(101) \n",
29+
" print \"Fibonacci Number is \", fib(n, lookup) \n",
30+
" \n",
31+
"if __name__==\"__main__\": \n",
32+
" main() "
33+
]
34+
}
35+
],
36+
"metadata": {
37+
"kernelspec": {
38+
"display_name": "Python 3",
39+
"language": "python",
40+
"name": "python3"
41+
},
42+
"language_info": {
43+
"codemirror_mode": {
44+
"name": "ipython",
45+
"version": 3
46+
},
47+
"file_extension": ".py",
48+
"mimetype": "text/x-python",
49+
"name": "python",
50+
"nbconvert_exporter": "python",
51+
"pygments_lexer": "ipython3",
52+
"version": "3.7.4"
53+
}
54+
},
55+
"nbformat": 4,
56+
"nbformat_minor": 4
57+
}

MISC/Stack.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 2,
66
"metadata": {},
77
"outputs": [
88
{

0 commit comments

Comments
 (0)