简体   繁体   中英

Finding all paths in graph, Python

I have a graph, represented in a way of a dictionary with pairs key|value - A node|Edges to other nodes . Example:

{'5': '1 2 3 W', '0': '1 2 3 W', '2': '0 4 5 L', '1': '0 4 5 L', '4': '1 2 3 W', '3': '0 4 5 L'}

( W and L are the marks of the nodes)
What is the best approach to find all the paths WLWL or LWLW ? (Python 3.+)

A "breadth first search" algorithm may be what you are looking for. You can find a good explanation and a Python implementation here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM