1. A method comprising: by one or more computing devices, accessing a binary decision diagram (BDD) representing a function having n variables, where n≧2, wherein: the BDD comprises n layers corresponding to the n variables, respectively; and the BDD has a first variable order where each variable i is at layer i for 1≦i≦n; and reordering the n variables of the BDD according to a second variable order denoted as π(i), where each variable i is at layer π(i) for 1≦i≦n, by iteratively and alternatingly swapping one or more first disjoint pairs of consecutive layers during each odd iteration and swapping one or more second disjoint pairs of consecutive layers during each even iteration, until the second variable order is achieved, wherein during each iteration, two consecutive layers are swapped only if a current order of two variables at the two consecutive layers differs from an order of the two variables specified by the second variable order.