Abstracting algorithms (graph depth first search)
Paul Moore
gustav at morpheus.demon.co.uk
Sat May 10 18:09:43 EDT 2003
"Raymond Hettinger" <vze4rx4y at verizon.net> writes:
> I took the class based approach and it is just a fast as a toplevel
> function. Users subclass the solver and supply ann iterator or
> generator for the edges from each node.
That's good to know. Instinctively, it felt like it would be slow, but
instinct isn't a particularly good guide here...
> The generic solver is about 25 lines.
That's the frustrating thing - writing this stuff really is easy in
Python. The problem comes in remembering the details of the
algorithms. I can write 25 lines of Python no problem. 25 *working*
lines seem to elude me, though :-) I'm still working through the
options and trying to decide whether the extra 25 lines of
infrastructure are worth the time saved making sure the algorithm's
correct :-)
But I was definitely right in one thing - graph algorithms are complex
enough to be interesting, without being too specialised to be worth
bothering with unless you have a specific need.
[Just wrote a Python version of some C++ graph code, which took a
fraction of the space, and was far more readable. Thanks, Guido :-)]
Paul.
--
This signature intentionally left blank
More information about the Python-list
mailing list