Simple depth first search algorithm implemented in java