M
M
markcpp2019-04-02 20:08:30
Algorithms
markcpp, 2019-04-02 20:08:30

How to search for the shortest path on a graph using an array of data?

There is an undirected graph:
5ca395793c2e2851732106.png
Is it possible (no matter what method) to find the shortest paths x1 -> x5 on a graph using an array of data? Where x1..x2 are values ​​from the table:
5ca3962d4c92d428342588.png
And in the response, get the table of paths:
5ca396606f65b721045253.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dmshar, 2019-04-02
@dmshar

Damn, people, have you already forgotten how to use Google or are you just too lazy *?
The first link gives the richest food for the brain:
https://habr.com/ru/post/119158/
And if you strain your brain a little and read what is written in the following three or four links, then you can already be cool specialist.
If you need to " just load an array and get an answer ", then there are quite a few such possibilities, for example, here is one of them:
https://github.com/pmatiello/python-graph
In general, the algorithm for finding the shortest path in a graph is studied in any specialty at least slightly related to IT.

R
Ruslan., 2019-04-08
@LaRN

Judging by the drawn graph, there are two options for the path:
1. x1-x2-x5
2. x1-x3-x4-x5
Of these two, you need to choose the smaller one.
The edge x2-x3 must be excluded, because in a triangle x1-x2-x3 it is always more profitable to choose one of the sides x1-x3 or
x1-x2 than two sides (x1-x2 + x2-x3 or x1-x3 + x3-x2).
Knowing this, a simple addition on your table is easy to find the answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question