0

I have a Directed Acyclic graph, something like this:

[a, b, c] --> [p, q] --> [p, a, c] --> [x, y, z]

Here, each of the alphabets is a node. From the above graph, I want the list of all the graphs having single nodes. eg One graph can be: a --> p --> a --> y Another can be: b --> p --> p --> z etc.

I can do a depth-first search (DFS) on the main graph to traverse it, but I'm not sure how to do multiple DFS to extract every graph having single character

2
  • Can you share any code example you did to try it, so we can try to take a look what might have gone wrong? Commented Apr 16, 2019 at 6:41
  • It is not acyclic... Commented Apr 16, 2019 at 6:43

1 Answer 1

1

If you have a list of the node sets you can do something like this -

from itertools import product
s =[[1, 2], [3, 4, 5], [6, 7]]
list(product(*s))

output -

[(1, 3, 6), (1, 3, 7), (1, 4, 6), (1, 4, 7), (1, 5, 6), (1, 5, 7), (2, 3, 6), (2, 3, 7), (2, 4, 6), (2, 4, 7), (2, 5, 6), (2, 5, 7)]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.