Tuesday, June 21, 2011

WAP to Find Two Leaf Nodes in Binary Tree such that F(x,y) is maximum

Given a binary tree, find 2 leaf nodes say X and Y such that F(X,Y) is maximum where F(X,Y) = sum of nodes in the path from root to X + sum of nodes in the path from root to Y - sum of nodes in the common path from root to first common ancestor of the Nodes X and Y


Data Structure: Binary Tree

Algorithm:


Working Code:




Time Complexity
Space Complexity

No comments :