Power of python recursion - Deepstash
Power of python recursion

Power of python recursion

Recursive function for calculating n! implemented in Python:

Behind the scenes, each recursive call adds a stack frame (containing its execution context) to the call stack until we reach the base case. Then, the stack begins to unwind as each call returns its results:

A demonstration should make things clearer. Let’s calculate 1 + 2 + 3 ⋅⋅⋅⋅ + 10 using recursion. The state that we have to maintain is (current number we are adding, accumulated sum till now) .

2

STASHED IN:

5

Deepstash helps you become inspired, wiser and productive, through bite-sized ideas from the best articles, books and videos out there.

GET THE APP:

RELATED IDEAS

Phone Interviews

Phone interviews are efficient time savers for both the candidate and the employer.

Initially considered a screening round for the benefit of the employer, a phone interview also helps the candidate weed out any potential deal-breakers before investing time, money, energy and resources to give a personal face-to-face interview (wherever that is happening).

12

STASHED IN:

218

Popping Bubble Wraps
  • There is something uniquely satisfying in popping sheets of bubble wraps and it seems to relate to the calming power of touch.
  • Studies on undergraduates showed that popping two sheets of bubble wraps made them feel calmer, awake and alert.
  • Popping bubbles is a way to release muscle tension, and just like clicking the pen or jiggling one's foot, it helps reduce stress and stabilize one's nervous energy.

1

STASHED IN:

24