Sujet : Re: filling area by color atack safety
De : 433-929-6894 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 17. Mar 2024, 18:11:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240317095014.365@kylheku.com>
References : 1 2 3 4 5 6
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-03-17, Malcolm McLean <
malcolm.arthur.mclean@gmail.com> wrote:
The convetional wisdom is the opposite, But here, conventional wisdom
fails. Because heaps are unlimited whilst stacks are not.
The strawman, absolutist conventional wisdom that "recursion is always
easier to analyze than iteration" is wrong in the first place.
Any program graph based on nothing but IF and GOTO primitives can be
mechanically transliterated into a (tail) recursive structure that has
the same shape, and is no easier to understand.
Your point is not very well made, though. Even though recursion may run
into a resource limit, its structure can still help analyze the logic of
the algorithm apart from that resource issue. The resource issue can be
separately analyzed and provisions made for the algorithm to handle the
required inputs, and reject others.
Most algorithms (especially ones working with all inputs in memory)
are constrained by resources. The iterative version of that image
processing algorithm might handle larger images than the recursive
one, but there are yet image sizes it won't handle.
The idea of calling algorithm implementations "incorrect" if they have
any limitations on their input sizes and such isn't particularly
informative or useful.
Obviously it is incorrect if something has limitations, and is used
in such a way that they are exceeded. E.g. the C <int> + <int>
operation when a result is implied that is beyond INT_MIN or INT_MAX.
Oops, + is not "correct"; don't use it!
Now, there is a bit of value in algorithms that will successfully
operate on any object that was successfully fit into memory. Do
these really exist though? Pretty much any algorithm implementation
requires some space to do its work, even if that space is small and
fixed. It's possible that the input fit into memory, yet that small and
fixed amount of space is not available.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca