in reply to OT(ish) - Best Search Algorithm

If you want to find all "circles of friends," i.e., all cycles to which you are a member, then you need to use a modified depth first traversal algorithm that begins and ends with you.

It is similar to finding all acyclic s-d paths, except in your case s and d (source and destination) are the same - you.

The algorithm is fast, especially if you don't have many friends - like most perl hackers :).
# Pseudo-code array dflabels[] for each node I in graph dflables[I] = 0 s := 0 d := 0 # same as "s", which is you # as recursive function acyclic (start_node) if 1 > dflabels[start_node]# max num visits is 1 dflabels[start_node]++ for each i in adjacent_nodes(start_node) acyclic(i) end for dflabels[start_node]-- # unlike strict dft decrement else # indicates we've been here before if start_node == s # check if this is YOU print "Cycle back to me found!" end if end if return end function acyclic # initiate call acyclic(s)
Of course, the above pseudo-code doesn't facilitate storing the actual paths, this is easily done using input and output parameters. Hope that helps.