[EDIT: I went through relevant questions on Stackoverflow, but they weren\'t helpful.]
I was thinking about writing an algorithm (a graph traversal algorithm) to determin