Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can any one solve this Problem

 
Praveen Reddy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can any one please help me by solving this problem.

Implement public Node GetLeastCommonAncenstor (Node m, Node n) such that it returns the node which has both m and n as a child. In the figure on the following page, passing the method nodes a and b will return node c because it is the first (least) node which contains both a and b. Please feel free to make any changes to the classes you feel are necessary; please document the changes and your reasons for making them. Note: the tree is a binary search tree, meaning that the nodes are sorted, with all the nodes on the left of each node being smaller than the nodes on the right.
public class Tree
{
public int GetNodeCount(Node n)
{
// return number of nodes
}
public Node GetLeastCommonAncenstor (Node m, Node n)
{
// return the least common ancenstor
}
}
public class Node
{
Node m_Left;
Node m_Right;
String m_Word;
}

Please check the below Sendspace link for Sample Binary Tree:



Thanks in Advance
Praveen
 
Praveen Reddy
Ranch Hand
Posts: 51
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65221
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your solution, and what problems are you having with it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic