13 Responses

  1. darth10
    darth10 27/11/2012 at 12:52 | | Reply

    Good read! :)

  2. Giulia
    Giulia 27/11/2012 at 13:16 | | Reply

    WOOOOOW :P

  3. hash
    hash 27/11/2012 at 14:15 | | Reply

    nice example. thanks for sharing.

  4. dbg
    dbg 27/11/2012 at 16:00 | | Reply

    maybe I’m just confused by terminology here. the factorial function defined with the accumulator is what I have been taught to call “memo-ization”. is this distinct in any way from tail recursion? based on what is explained in the article here it looks like the terms are synonyms. can somebody provide an example of a memo-ized recursive algorithm that is NOT tail recursive?

    1. inemnitable
      inemnitable 27/11/2012 at 16:22 | | Reply

      Memoization is a technique in which the results of calling a function on a particular set of arguments are stored in a data structure (usually a hash table) indexed by those arguments before returning, so that subsequent calls to that function with the same arguments can simply return the result stored in the table rather than performing potentially expensive calculations instead. It’s mostly useful in situations where you would expect to be calling the same function with the same arguments many times, especially during recursion.

  5. Lucas
    Lucas 27/11/2012 at 16:02 | | Reply

    Excellent share. Very interesting.

  6. dave parker
    dave parker 27/11/2012 at 16:34 | | Reply

    its its its its its its its its its its its its its its its its its its its its its its its its its its thank you

  7. Yousif
    Yousif 27/11/2012 at 18:35 | | Reply

    Nice.
    But you missed the final method call before 120 is returned.


    factorialIter(0, 120)
    120

    Or did I misunderstand something? :)

  8. Joe
    Joe 28/11/2012 at 02:22 | | Reply


    def path_count(x, y):
    return 1 if x <= 0 or y <= 0 else path_count(x-1, y) + path_count(x, y-1)


    def path_count(x, y):
    def c_iter(x, y, acc):
    return acc if x <= 0 or y <= 0 else c_iter(x - 1, y, acc + path_count(x, y -1))

    return c_iter(x, y, 1)

Leave a Reply


three + = twelve

* Copy This Password *

* Type Or Paste Password Here *