C # graph trace - tracking path between any two nodes

Look for a good approach to track the Breadth-First intersection between two nodes without knowing anything about the graph. Versus Depth-First (where you can throw the path if it doesn’t fall out), you can have quite a few β€œopen” options during the traversal.

+3
source share
4 answers

The naive approach is to build a tree with the source node as the root and all its connections as its children. Depending on the amount of space that you have, you may need to eliminate cycles when you go. You can do this with a bitmap, where each bit corresponds to a separate node in the graph. When you reach the goal of the node, you can go to the parent links to the root, and that is your way. As you advance in width first, you are sure that this is the shortest path, even if you do not eliminate the loops.

+2
source

. - , - , , . , . node (s), node node ( ) .

(.. ) -. , "" , . , - ( (57509), ( ) , - . , , ( ) node, . , , , .

, . (- , , .)

+1

, .

, ( ) . node . .

+1

.NET 3.5, Hashset, , , . - , A * search, . , , .

If you're still a fan of treeware, there are many great books on graphs and graph searches, such as Artificial Intelligence: A Modern Approach by Peter Norwig and Stuart Russell.

The links in my answer have the error that they are Hashset: http://msdn.com/en-us/library/bb359438.aspx and A * search: http://en.wikipedia.org/wiki/A* _search_algorithm

0
source

Source: https://habr.com/ru/post/1696819/


All Articles