Tom Ellis
Tom Ellis

Reputation: 9434

Name for algorithm reconstructing tree from lowest common ancestor?

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

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.

Upvotes: 3

Views: 147

Answers (1)

btilly
btilly

Reputation: 46542

I don't know what you call it, but I'd first compare all pairs of elements to construct the partial order for the tree, then do a topological sort, then construct the tree from that. (The point of sorting it is that now you know that the first element is the root, and each element in turn will be a leaf.)

The subject reminded me of cladistics algorithms, http://bio.slu.edu/mayden/systematics/bsc420520lect12.html. However those are both easier and harder. Easier because it is easy to tell upon inspection which forms are close to another. Harder because the challenge is that you don't know the LCA. So pursuing that might be an interesting side track but is probably not very helpful.

Upvotes: 1

Related Questions