Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Whether it does tail call optimization is a different question than whether you can write the algorithm in a tail-recursive manner, though.


Yes, but without the optimization, how would it help? Am I just being a n00b?


Writing it tail-recursively forces you to switch from the O(2^n) algorithm (which has two recursive calls; you can't put both into tail position) to a more efficient algorithm. You could also write the more-efficient algorithm without tail recursion, of course.


No, you're not being a n00b. It'll help because the stack usage will grow linearly as opposed to quadratically, as in the case of the naive solution. You'll still overflow the stack without the optimization.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: