Question: Stage 2 : DFS strategy In this stage a DFS strategy must be implemented. When following this strategy, the detective maps out an entire route
Stage : DFS strategy
In this stage a DFS strategy must be implemented. When following this strategy, the detective maps out an entire route that will take them through every city on the map using the DFS algorithm. If the DFS has a choice between multiple cities, it must prioritise the city with the lowest ID At every cycle, the detective attempts to move to the next city on the plan. If the detective does not have enough stamina, they must wait in the same city to recover. As soon as the detective has visited all cities at least once, a new DFS path from the final location is mapped out and is followed.
For example, consider the following arrangement of cities and roads:
If a detective using the DFS strategy starts at city then they should devise the following route: rightarrow rightarrow rightarrow rightarrow rightarrow rightarrow rightarrow rightarrow rightarrow rightarrow rightarrow rightarrow rightarrow The route ends at city because once the detective reaches city they will have visited all the cities, and the next DFS would begin at city
You can assume that the maximum stamina of each detective using the DFS strategy is greater than or equal to the length of the longest road, so no detective using the DFS strategy will be stuck forever at some city while trying to complete their route.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
