The ordering doesn't matter, since we only take the states that have 0 un-visited dependencies. If there are 2 states without un-visited dependencies, it means they can be visited in any order (and in fact we visit them all at once).

If we iterated on `stateMap.entrySet()` instead of `remainingStates`, we'd have to do an additional lookup for each key into `remainingStates`, for a total of N^2 hash lookups. But `remainingStates` goes down in size with every iteration, so this way we have N*(N-1)/2 lookups.