I'd like to write a tool that works on some tree-structured data. (In fact it will work on a tree-like subset of a git revision DAG, but that's not important for this question). In particular I want an algorithm that reconstructs a subset of the tree consisting of all the "join points" of a given input set.
Specifically what I think I want is
We have some type
H
that has a "lowest common ancestor" function,lca
on it. This givesH
a tree-like structure.The algorithm takes some subset
S
ofH
as input.The output should be a multi-way tree
t
with nodes labelled by values ofH
.t
should satisfy the propertiesAll
s
inS
label some node oft
The leaves of
t
can only be labelled by elements ofS
Any element
h
forH
labels no more than one node oft
If
h1
labelsn1
andh2
labelsn2
thenlca(h1, h2)
labels the lowest common ancestor ofn1
andn2
int
.
My question is: "Is this a known problem with known algorithms?". I suspect it is. It seems quite similar to a topological sort. I have an idea for an algorithm based on merge sort but if known algorithms already exist there's no reason to come up with my own.