Yes, the order in the array matters. Se above comment about Tarjan's algorithm.