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
Hthat has a "lowest common ancestor" function,lcaon it. This givesHa tree-like structure.The algorithm takes some subset
SofHas input.The output should be a multi-way tree
twith nodes labelled by values ofH.tshould satisfy the propertiesAll
sinSlabel some node oftThe leaves of
tcan only be labelled by elements ofSAny element
hforHlabels no more than one node oftIf
h1labelsn1andh2labelsn2thenlca(h1, h2)labels the lowest common ancestor ofn1andn2int.
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.