Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #158167

Re: Recursion v Memoization

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Recursion v Memoization
Date 2021-01-04 19:56 -0800
Organization A noiseless patient Spider
Message-ID <86h7nwrq8s.fsf@linuxsc.com> (permalink)
References <rsg72i$eq4$1@gioia.aioe.org> <861rf6uzw4.fsf@linuxsc.com> <1b1rf2zsuf.fsf@pfeifferfamily.net>

Show all headers | View raw


Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:

> Recursive Fibonacci is actually a great function to go through in a
> beginning programming class, because you can use it to show
>
> (1) how recursion works.  By the time the students have Fibonacci
>     working recursively, they're got at least an inkling of the
>     process.
>
> (2) why recursion can be *horrible* choice for a solving a problem.
>     It was even better for this back in the days of 386s and the
>     like, because you could have a call that went for several
>     minutes but eventually came back with the right answer.
>
> (3) how to use a static array to add memoization to a recursive
>     function to get something of the best of both worlds.

I don't find these reasons persuasive.  Computing fibonacci
through double recursion is not an obvious algorithm but it is
obviously a dumb algorithm.  The lesson is not that recursion
is horrible but that bad algorithms are horrible, which in turn
removes the motivation for memoization, because it isn't really
necessary here.  (In fact I'm not sure where it is necessary,
but that's a separate discussion.)

Teaching recursion should start first with single recursion, with
a good choice being the familiar problem of greatest common
divisor.  If one then wants to give naive recursive fibonacci as
a bad example, fine, but it isn't the right place to start.  And,
if recursive fibonacci /is/ given as a bad example, it should be
closely followed by an example of double recursion where the
recursion helps rather than hurts.  Two possible choices for that
are merge sort (naturally recursive) or computing factorials of
large numbers (where subdividing recursion isn't obvious but
gives a huge speedup over the more obvious iterative algorithm).

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Recursion v Memoization Real Troll <real.Troll@trolls.com> - 2020-12-29 16:30 -0500
  Re: Recursion v Memoization Bart <bc@freeuk.com> - 2020-12-29 22:17 +0000
    Re: Recursion v Memoization Ike Naar <ike@sdf.org> - 2020-12-30 05:47 +0000
      Re: Recursion v Memoization Bart <bc@freeuk.com> - 2020-12-30 11:55 +0000
  Re: Recursion v Memoization "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-12-29 21:51 -0800
  Re: Recursion v Memoization Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-12-31 00:46 -0800
    Re: Recursion v Memoization David Brown <david.brown@hesbynett.no> - 2020-12-31 16:12 +0100
      [OT] was: Recursion v Memoization Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-01-01 15:59 +0000
        Re: [OT] was: Recursion v Memoization David Brown <david.brown@hesbynett.no> - 2021-01-01 17:35 +0100
        Re: [OT] was: Recursion v Memoization Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-01-01 08:40 -0800
        Re: [OT] was: Recursion v Memoization Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-01-02 10:36 -0800
          Re: [OT] was: Recursion v Memoization "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-01-02 16:59 -0800
          Re: [OT] was: Recursion v Memoization "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-01-02 17:00 -0800
    Re: Recursion v Memoization Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-01-02 18:56 -0700
      Re: Recursion v Memoization Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-01-04 19:56 -0800
        Re: Recursion v Memoization beej@beej.us (Beej) - 2021-01-05 04:27 +0000
          Re: Recursion v Memoization Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-01-07 04:54 -0800
            Re: Recursion v Memoization beej@beej.us (Beej) - 2021-01-11 05:43 +0000
              Re: Recursion v Memoization Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-01-11 06:34 -0800
        Re: Recursion v Memoization Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-01-05 14:35 -0700
          Re: Recursion v Memoization Real Troll <real.troll@trolls.com> - 2021-01-05 16:45 -0500
            Re: Recursion v Memoization Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-01-05 15:33 -0700
          Re: Recursion v Memoization Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-01-06 09:40 +0000
            Re: Recursion v Memoization Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-01-06 17:09 +0000
          Re: Recursion v Memoization Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-01-07 06:37 -0800
  Re: Recursion v Memoization Andrey Tarasevich <andreytarasevich@hotmail.com> - 2020-12-31 02:33 -0800

csiph-web