-1
$\begingroup$

I'm trying to model a questionnaire where the flow between questions depends on the answers given in previous questions.

Example. (Node represent questions, edges represent answers).

As you can see there are 2 parallel edges from nodes A to B, each representing an answer to the first question (node A). Node B (the second question) has 4 edges but they each depend on both the answer to A and the answer to B.

i.e. A > 1 > B > 1 > C (answering 1 to the first question means that only the green edges from B are "valid").

A secondary question (and the actual question I'm looking to answer) would be, given a graph like the above (of arbitrary complexity), is there a generalised algorithm to determine which edges are "valid" / "invalid" depending on the route taken?

Any guidance much appreciated!

$\endgroup$

1 Answer 1

0
$\begingroup$

Those graphs can be transformed to binary trees by letting the node that corresponds to the first question be the root and duplicating the node that corresponds to the next question; one for each possible answer to the previous question.

These binary search trees are easier to handle, than your representation; if you are worried about duplicating the text of the question, you can also store a pointer to the text in the nodes.

$\endgroup$
1
  • $\begingroup$ Yes, this was another option that I was exploring and probably the easiest now I think about it. Thanks for the reply, Manfred. $\endgroup$
    – jxd
    Commented May 12, 2017 at 10:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .