Recursion?🤔dynamic programmming???🙃🙂 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Recursion?🤔dynamic programmming???🙃🙂

def manu(x): if x == 1: return 0 if x == 2: return 1 else: return manu(x - 1) + manu(x - 2) print(manu(10)) 34 is the answer when we execute this code snippet in any IDE.Can geeks tell me how do we get that?(i feel like we should use dynamic programming concept here but still want to sense that with ur good procedure) Hoping ur answers......

16th Aug 2020, 11:29 AM
$GEEK~(🤔BM.MARESH✌😜)
$GEEK~(🤔BM.MARESH✌😜) - avatar
1 Answer
+ 2
For ex: manu(5) : returns => manu(5-1) + manu(5-2) => manu(4) + manu(3) => manu(4-1)+manu(4-2)+manu(3-1) +manu(3-2) =>manu(3)+manu(2) + manu(2) + manu(1) =>manu(3-1)+manu(3-2) + manu(2) +1+0 => manu(2) + manu(1) + 1 +1 => 1 + 0 + 1 +1 => 3 Simalar way for 10.
16th Aug 2020, 11:55 AM
Jayakrishna 🇮🇳