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 | |
by locked_user sundialsvc4 (Abbot) on Oct 15, 2010 at 17:08 UTC |