My laptop lags when I am using this recursive function.WHY? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

My laptop lags when I am using this recursive function.WHY?

Although I am using a base case, my laptop cannot run the function: def compute(n): if n==1: return 1 else: return (n**2) + compute((n-1)**2)

7th Sep 2017, 5:55 PM
Mohammed Abdulhady
Mohammed Abdulhady - avatar
1 Answer
+ 2
You maybe rather want to do: def compute(n): if n==1: return 1 else: return (n**2) + (compute(n-1)**2) ;)
7th Sep 2017, 7:32 PM
visph
visph - avatar