Depth first search on an array of nodes