Skip to content

How do I efficiently find the grand MRCA in a tree? #1490

Answered by jeromekelleher
hyanwong asked this question in Q&A
Discussion options

You must be logged in to vote

Unless the tree has a very large number of unary nodes above the root, then traversing down will be more efficient:

mrca = tree.root
while tree.num_children(mrca) == 1:
      mrca = tree.left_child(mrca)

(This will break in some corner cases, but should be the right option most of the time)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jeromekelleher
Comment options

Answer selected by hyanwong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants