http://www.python-course.eu/recursive_functions.php
http://en.m.wikipedia.org/wiki/Graph_traversal
( depth first approach is good for all things Maya related )
Basically it's a function that keeps calling itself until it doesn't find any further branches to climb
Works great in Maya for all things connected to any other thing, similar to how the Houdini tree traversal worked before they botched the core traversal with subnets..
It's quite fun to write, in pseudo-code ( am on a phone, just answering since you haven't gotten one yet, will send you an actual example later ) :
Def crawl:
For thing found:
Tag checked
Call crawl on all results
Return
Eventually it runs out of things to do and returns, kind of like a while loop but instead of a parameter that stops it, it always stops when there is nothing else to do.
Hope this helps, and you have fun reading the links, the wording in there sounds a lot more than the trick is.