]> ZDDs - Constructing ZDDs

## Constructing ZDDs

Given a family $F$ of sets, we can find its ZDD as follows.

1. If $F=\varnothing$ ($F$ is empty) return $\perp$. If $F=\epsilon$ ($F$ contains only the empty set) then return $\top$.

2. Find the smallest element $v$ amongst all elements in all sets of $F$. Create a node $v$.

3. Let ${F}_{0}$ be the family of all sets in $F$ not containing $v$, that is, ${F}_{0}=\left\{\alpha :\alpha \in F,v\notin \alpha \right\}$. Recursively construct the ZDD for ${F}_{0}$, and connect the LO edge from $v$ to the root of ${F}_{0}$.

4. Let ${F}_{1}$ be the family resulting from taking all sets in $F$ that contain $v$ and then removing $v$ from each set: ${F}_{1}=\left\{\alpha \setminus \left\{v\right\}:\alpha \in F,v\in \alpha \right\}$. Recursively construct the ZDD for ${F}_{1}$, and connect the HI edge from $v$ to the root of ${F}_{1}$.

5. Look for identical nodes (same label, same LO desination and same HI destination) and combine them.

Some families have special properties allowing their ZDDs to be immediately constructed. In a universe of size $n$, consider for example the family of all sets of size $k$ which we denote ${S}_{k}\left(\left\{1,...,n\right\}\right)$. The ZDD of ${S}_{2}\left(\left\{1,2,3\right\}\right)=\left\{\left\{1,2\right\},\left\{2,3\right\},\left\{1,3\right\}\right\}$ is the following:

The ZDD of ${S}_{k}\left(\left\{1,...,n\right\}\right)$ turns out to be easy to describe (exercise).

Here are some more examples. Let $U=\left\{1,...,6\right\}$. Then the ZDD of all sets containing exactly one of $S=\left\{2,3,5\right\}$ is:

The ZDD of all sets containing at least one element of $S$ is:

The ZDD of all sets containing at most one element of $S$ is:

These 3 examples are readily generalized. Each can be viewed as a ZDD of all sets that branches off at the smallest element of $S$, before joining the main branch again after the largest element of $S$ has been handled.

In many combinatorial problems, we start with families that can be immediately written down. We then perform operations on these families to construct other families which we use to solve the problem. For example, given ZDDs $F$ and $G$, we construct $F\cup G$, or $F\cap G$, or $F\bigsqcup G$, or similar.