0

I am working on a problem in graphs and trying to figure out on finding unique paths

let me give an example, let us consider a graph with 4 nodes and 6 edges with edges as follows -

1 2
2 3
3 4
4 1
1 3
2 4

the unique cyclic paths of length 5 will be -

  1. 1 -> 2 -> 3 -> 4 -> 1

  2. 1 -> 3 -> 2 -> 4 -> 1

  3. 1 -> 2 -> 4 -> 3 -> 1

    Two paths are considered equal if the set of edges of the path are equal. consider the two paths 1 -> 2 -> 3 -> 4 -> 1 and 1 -> 3 -> 2 -> 4 -> 1 The first path is just the set = [(1,2), (2,3), (3,4), (4,1)], while the second is = [(1,3), (3,2), (2,4), (4,1)]
    Clearly, the two sets are different, and hence so are the paths. The ordering of the edges are irrelevant as you're only comparing for the presence of the common edges between any two sets (paths).

Once I get the cyclic paths, how do i check if the paths have the same set of nodes in the path? i.e , 1 -> 2 -> 3 -> 4 -> 1 and 1 -> 4 -> 3 -> 2 -> 1 have the same sets, i.e
[(1,2), (2,3), (3,4), (4,1)] in a different order.
I thought of implementing a map of pair of sets and checking for duplicates.. still looking for better options. Any help is appreciated on how to proceed?

Community
  • 1
  • 1
joe bill
  • 1
  • 2

1 Answers1

0

Have you considered using Python Patterns - Implementing Graphs. Its an excellent resource. I used it to solve for a programming contest question on unique paths in a graph from vertex x to y.enter link description here

Jubin Chheda
  • 534
  • 4
  • 11