Tail and Non-Tail Recursion in Python 3

preview_player
Показать описание
0:00 Introduction
0:55 The Return Statement
3:38 Recursive Fn w/out Return Statement
7:34 Coding a Non-Tail Recursive Factorial fn
11:35 Tracing NTR Factorial
21:20 Coding a Tail-Recursive Factorial fn
26:04 Tracing a Tail-Recusrive Factorial fn
30:19 Wrap-up

Background Music Used:
Creative Commons Attribution 3.0 Unported License
Рекомендации по теме
Комментарии
Автор

This video was super helpful to me. Thank you so much!

shreyaghosh
Автор

24:50 try setting a default value for your for accumulator like this:

def fac2(n, A = 1):
#base case
#return accumulator
#recursive step
#return tail recursion

this way you just need 1 argument to run your function (the value of n). Also, when you set a default value to your accumulator it becomes an attribute of the function object you created.
This way the default value of the accumulator in your function object will be available as:

fac2.__defaults__

anonlegion