Home python python. Search for a brief path in the graph

python. Search for a brief path in the graph

Author

Date

Category

Suppose there is any graph.
According to the result, I write it into the dictionary and comes out something like that, for example:
{0: {1, 3}, 1: {0, 2}, 2: {1, 3}, 3: {0, 2}}
Point: {Available paths} – respectively.
How to organize the search for the shortest path?

With this feature, I have implemented simply searching the way, but not brief:

def int_path (graph, start, end, path = []):
  Path = Path + [Start]
  IF Start == End:
    Return Path.
  IF Not Start In Graph.keys ():
    Return none
  For Node in Graph [Start]:
    If Node Not in Path:
      Newpath = Find_Path (Graph, Node, End, Path)
      If NEWPath: Return Newpath
  Return none

Answer 1, Authority 100%

Looking for the shortest path on the column must be implemented not on the Nativity, but to first familiarize yourself with the relevant theory.

https://ru.wikipedia.org/wiki/zadach_O_Kratchay_Puta

Well, if lazy to learn, then at least on the Internet find how this task is offered to solve others, who was not laziness:

https://habr.com/ru/post/119158/

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions