A "generic" graph traversal algorithm