Graph connections in python -


i'm not familiar graph theory, i'll try explain problem. have dictionnary this:

{67: [68, 332],  68: [67],  265: [266],  266: [265],  332: [67, 333],  333: [332, 334],  334: [333, 335],  335: [334, 336],  336: [335]} 

the keys of dict nodes, , values edges of graph. how can find connected groups in graph? [there 2 groups - 265->266 , 67->...->366]

it looks graph undirected, meaning that, 2 nodes , b, if there edge b there edge b a. find connected components of graph, can use depth-first search. start @ node , follow edges until can't reach more nodes without hitting duplicates. first connected component. start @ node haven't touched yet , repeat. you're done when you've reached nodes in graph.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -