Answer:
Algorithm:
Find the name of the source vertex from column 1 of grid.
Get the name of the target vertex from user input.
Initialize an empty list to store the path from source to target.
Add the target vertex to the end of the path list.
While the target vertex is not the source vertex: a. Find the row in grid that corresponds to the target vertex. b. For each ancestor vertex (parent) in the row: i. Check if the distance from the source vertex to the ancestor vertex plus the distance from the ancestor vertex to the target vertex equals the distance from the source vertex to the target vertex. ii. If it does, add the ancestor vertex to the beginning of the path list and set the target vertex to the ancestor vertex.
Return the path list.
To find the source vertex in real code, we can search for the vertex with the shortest distance from the source vertex in the results grid. This vertex will be the source vertex.
I did not run into any challenges in developing this algorithm.
No, I did not have to use any other collection for this algorithm since the path is stored in a list.
Step-by-step explanation: