• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: The closest path between two points in terms of time

Resolved: The closest path between two points in terms of time

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

In this code, all path between two point s and d is print.
If the element (i,j) of the matrix “adjacency_matrix” represents the time required to go from point i to point j, how can the following program be changed, instead of print all paths, save all the paths and corresponding time to pass that paths, display the shortest path?

Answer:

Add another parameter paths to the recursion. Each time you recurse to the deepest point, add a copy of the current path to paths:
Test:
Update:
I noticed that you need the path with the shortest cost rather than the path with the least number of points, so I stored the cost value in the matrix into the value of the dictionary and adjusted the structure of your class:
Test:

If you have better answer, please add a comment about this, thank you!

matrix python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Passing 2 functions in onChange in react

24/03/2023

Resolved: Why doesn’t stringstream consume output during hex formatting?

24/03/2023

Resolved: CMake path for python3 libraries doesn’t change (windows 10)

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.