Browsing the archives for the Trees category

Challenge – First Common Ancestor

Question: How would you find the first common ancestor of two nodes in a binary search tree? First as in the lowest in the tree. Another way to ask is to find the lowest common ancestor of two nodes. Challenge: Do you know the answer to this question? Post in the comments. Answers will be posted […]

Balanced Tree

Question: How would you check if a binary tree is balanced? Answer: A tree is considered balanced when the difference between the min depth and max depth does not exceed 1. Recursive algorithms always work well on trees, so here’s some code. int min_depth( Node * root ) { if( !root ) { return 0; […]