I have the following directed graph implementation
Nodes nod[]
List<Arcs> arc[]
So the node on the n’th position has all his arcs of the list in position n. Of course, the nodes are organized accordingly, so that I can use Binary Search.
Based on this implementation. I wish to create a DFS algorithm. I know very well the pseudo code, adapting to java shouldn’t be a problem.
But my question is the following. In DFS we need to start searching from the “top” node. And thinking about it, i dont have this “top” node. Moreover, I have no idea how to get it.
So I ask, how do i get this top node, considering my implementation?
Thanks for the help.
Expanding on my comment:
Assuming that the arcs are directed (i.e., from the parent node to the child only) you can search all of the nodes for the one with no incoming arcs: