<p>We can reduce it to the following problem:</p>

<blockquote>
  <p>Given a directed graph on vertex set $\{1,2,\dots,n\}$, we want to know if there exists a permutation $T$ such that for each edge $(i,j)$ in the graph, $T[i]&lt;T[j]$.</p>
</blockquote>

<p>The reduction: add an edge to the graph for each pair $i,j$ where both $P_b[i]$ and $P_b[j]$ exist for some $b \in \{0,1\}$; the orientation of the edge is determined by whether $P_b[i]&lt;P_b[j]$ or not.  This yields a directed graph that contains the union of edges from $P_0$ plus edges from $P_1$.</p>

<p>Conveniently, the new problem is easy.  Of course, if there are any cycles in the graph, then there is no such permutation $T$ (i.e., the two permutations $P_0,P_1$ are not compatible).  Conversely, if there are no cycles in the graph, then there is such a permutation $T$ (i.e., the permutations $P_0,P_1$ are compatible).  Do you see why?  We can simply apply a topological sort to the graph and use it to construct an example of such a permutation $T$, where we assign $T[i]=j$ if vertex $i$ is the $j$th vertex to be visited in the topologically sorted order.</p>

<p>I'm not sure what BDDs have to do with it.  This does not seem like a research-level question.</p>

CC BY-SA 3.0
2014-01-09T21:28:00.797Z
This is usable. And yes, I am interested in the implementation not only in a pure theoretical knowledge - therefore I also asked for the proper data structure. Comment on BDDs: if two OBDDs have different but compatible variable ordering (they do not include all variables) then you can use standard efficient algorithm to compose them and you will obtain a valid OBDD - this is just a brainstorming idea, we do not have any results, yet.
meolic
CC BY-SA 3.0
2014-01-06T09:43:50.997Z
2014-01-06T09:43:50.997Z
D.W.
<p>Please, correct my terminology as I am not a combinatorician
(I am using <a href="http://en.wikipedia.org/wiki/Partial_permutation" rel="nofollow">http://en.wikipedia.org/wiki/Partial_permutation</a>). Please, refer me to the solution if this is a solved problem.</p>

<hr>

<p>Let $P_k$ be partial permutations of the set $\{1, 2, \ldots, n\}$, e.g. $n=5$, $P_1=(1,\cdot,3,2,\cdot)$, and $P_2=(\cdot,2,3,1,5)$. Let $T_k$ be permutations from the same set, e.g. $T_1=(1,3,4,2,5)$.  I will write $P_1[4]=2$, $P_2[4]=1$, and $T_1[4]=2$.  I will say, that $P_1[2]$, $P_1[5]$, and $P_2[1]$ do not exist.</p>

<p>Let define that a given partial permutation $P$ is included in the given permutation $T$ if for all $i,j$ for which $P[i]$ and $P[j]$ exist: if $P[i] &lt; P[j]$ then $T[i] &lt; T[j]$. For example, the given $P_1$ and $P_2$ are both included in the given $T_1$.</p>

<p>Let define that two given partial permutations are compatible if there exists a permutation such that both partial permutations are included in it. For example, the given $P_1$ and $P_2$ are compatible, because they are both included in $T_1$.</p>

<p>QUESTION: Propose an algorithm to check if two given partial permutations are compatible. Please propose also the proper data structure for representing partial orders which will allow your (efficient) algorithm.</p>

<p>(I am tagging this question with BDD because the solution may help me to represent BDDs with different variable ordering more concisely)</p>

<sorting><permutations><partial-order><binary-decision-diagrams>
Compatible partial permutations
meolic
# Compatible partial permutations

(Asked by: username_0 on 2014-01-05)

Please, correct my terminology as I am not a combinatorician
(I am using <http://en.wikipedia.org/wiki/Partial_permutation>). Please, refer me to the solution if this is a solved problem.

---

Let $P\_k$ be partial permutations of the set $\{1, 2, \ldots, n\}$, e.g. $n=5$, $P\_1=(1,\cdot,3,2,\cdot)$, and $P\_2=(\cdot,2,3,1,5)$. Let $T\_k$ be permutations from the same set, e.g. $T\_1=(1,3,4,2,5)$. I will write $P\_1[4]=2$, $P\_2[4]=1$, and $T\_1[4]=2$. I will say, that $P\_1[2]$, $P\_1[5]$, and $P\_2[1]$ do not exist.

Let define that a given partial permutation $P$ is included in the given permutation $T$ if for all $i,j$ for which $P[i]$ and $P[j]$ exist: if $P[i] < P[j]$ then $T[i] < T[j]$. For example, the given $P\_1$ and $P\_2$ are both included in the given $T\_1$.

Let define that two given partial permutations are compatible if there exists a permutation such that both partial permutations are included in it. For example, the given $P\_1$ and $P\_2$ are compatible, because they are both included in $T\_1$.

QUESTION: Propose an algorithm to check if two given partial permutations are compatible. Please propose also the proper data structure for representing partial orders which will allow your (efficient) algorithm.

(I am tagging this question with BDD because the solution may help me to represent BDDs with different variable ordering more concisely)

**Tags:** sorting, permutations, partial-order, binary-decision-diagrams

---

## 1 answers

### Answer by username_1 on 2014-01-06. Score: 2 | Accepted answer

We can reduce it to the following problem:

> Given a directed graph on vertex set $\{1,2,\dots,n\}$, we want to know if there exists a permutation $T$ such that for each edge $(i,j)$ in the graph, $T[i]

The reduction: add an edge to the graph for each pair $i,j$ where both $P\_b[i]$ and $P\_b[j]$ exist for some $b \in \{0,1\}$; the orientation of the edge is determined by whether $P\_b[i]

Conveniently, the new problem is easy. Of course, if there are any cycles in the graph, then there is no such permutation $T$ (i.e., the two permutations $P\_0,P\_1$ are not compatible). Conversely, if there are no cycles in the graph, then there is such a permutation $T$ (i.e., the permutations $P\_0,P\_1$ are compatible). Do you see why? We can simply apply a topological sort to the graph and use it to construct an example of such a permutation $T$, where we assign $T[i]=j$ if vertex $i$ is the $j$th vertex to be visited in the topologically sorted order.

I'm not sure what BDDs have to do with it. This does not seem like a research-level question.

> **Comments:**
> **username_0**: This is usable. And yes, I am interested in the implementation not only in a pure theoretical knowledge - therefore I also asked for the proper data structure. Comment on BDDs: if two OBDDs have different but compatible variable ordering (they do not include all variables) then you can use standard efficient algorithm to compose them and you will obtain a valid OBDD - this is just a brainstorming idea, we do not have any results, yet.  

---

