in reply to Arbitrarily Nested HoH

Recursion is a very powerful technique, and fairly cheap to do.   Lately, I have also found useful the notion of a “work-to-do stack,” in which we push the first item(s) onto the stack initially, and then repeat a process in a simple loop until the stack becomes empty.   As more work is discovered, it is pushed onto the stack (or stacks, as the case may be).

This is, of course, very similar to recursion in the simple case, but it can come in handy when “the case” becomes “not quite so simple,” e.g. when there might need to be a choice concerning “what to do next.”   (Priorities, prerequisites, and so forth ...)   A recursion is always FIFO (“first-in first-out”), but this does not have to be.   All the work will eventually get done, no matter how much work there is, but it is not strictly obliged to be FIFO.

Replies are listed 'Best First'.
Re^2: Arbitrarily Nested HoH
by MidLifeXis (Monsignor) on Oct 15, 2010 at 14:58 UTC

    Perhaps I am misunderstanding your comment, but if your recursion uses a stack (which, I would say, at least the calls do), the solution has to be LIFO. A queue would be FIFO.

    This could just be a difference between understanding your comment differently than the way you meant to say it.

    --MidLifeXis

      Stack.   Queue.   Whatever.   :-D

      “Verily, verily, I code unto thee:   he who seeks to be first, shall be last...”   :-;

      You store the items, in some method and according to some suitable discipline, and then you “work through the list(s).”   That’s the gist of it.