[Tutor] learning recursion

Dave Angel davea at davea.name
Sun Feb 9 19:56:46 CET 2014


 Russel Winder <russel at winder.org.uk> Wrote in message:
> On Thu, 2014-02-06 at 18:06 -0500, Dave Angel wrote:
> […]
>> 
>> Code:
>> def fib2(n):
>> 	if n==1:
>> 		return 1
>> 
>> 	elif n==2:
>> 		return 1
>> 	else:
>> 		return fib2(n-2) +fib2(n-1)
> […]
> 
> I suggest it also be pointed out that this form is algorithmically
> dreadful. Having transformed the maths to this first cut code, we then
> need to consider it as code and shift to a tail recursive form,
> iterative form, or at the very least memoize the function. Leaving
> students of programming (in any current language) with the idea that
> this is a good final solution is, I believe, a disservice. 
> 
>
Not as bad as attributing that code to me.



-- 
DaveA



More information about the Tutor mailing list