To let $ T $ be a tree with $ V $ and edges $ E $. Let a **linear arrangement** $ pi $ of $ T $ a bijective mapping of nodes to integers in the range $ {1, dots, | V | } $. you can imagine $ pi $ as defining the position of each node in an array on a line.

Now define the **length** an edge $ E = {u, v } $ in the $ T $ under $ pi $ be the absolute value of the position difference for $ u $ and $ v $ according to the linear arrangement $ pi $::

begin {equation}

l_ pi (u, v) = | pi (u) – pi (v) |.

end {equation}

Linear arrangements of this kind are examined, for example, in the problem of optimal linear arrangement (Chung, 1984), where the goal is to find a $ pi $ for a firm $ T $ which minimizes $ sum _ { {u, v } in E} l_ pi (u, v) $.

My problem is: given a tree $ T $ and a linear arrangement $ pi $, create new linear arrangement $ pi ^ prime $ randomly uniform from the set of possible linear arrangements of $ T $ while maintaining the same distribution over the edge lengths as in the original $ pi $.

An example tree with a linear arrangement $ pi $ is shown below. Each edge is marked with its length. The distribution of edge lengths in this tree is under this particular linear arrangement $ (1, 1, 1, 2, 2) $ (3 of length 1 and 2 of length 2).

Here is the same tree under a different linear arrangement $ pi ^ prime $that has the same distribution of edge lengths $ (1,1,1,2,2) $.

I'm looking for an efficient algorithm to generate random linear arrays that maintain the distribution over edge lengths. Here is a basic algorithm for rejecting samples:

- Start with the tree $ T $ With $ n $ Knot and linear arrangement $ pi $Calculate the list of edge lengths for $ T $ under $ pi $. Call that $ L $.
- Generate a random linear arrangement $ pi ^ prime $ by drawing from the set of $ n! $ linear arrangements of $ T $.
- Calculate the list of edge lengths for $ T $ under $ pi ^ prime $. Call that $ L ^ prime $. If $ L ^ prime = L $, take the sample. If $ L ^ prime neq L $, reject the sample and go to step 2.

This question relates to my previous question, but differs from this one: Generate a randomly labeled tree with restricted edge lengths. In this question I looked for random trees. In this question, I am looking for random linear arrangements of a fixed tree, while maintaining the topology of the tree.