GeeCON Prague 2014*
The moose likes Java in General and the fly likes Can any one solve this Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Can any one solve this Problem" Watch "Can any one solve this Problem" New topic
Author

Can any one solve this Problem

Praveen Reddy
Ranch Hand

Joined: Jul 12, 2006
Posts: 51
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

Joined: Jul 12, 2006
Posts: 51
Image Link

http://www.sendspace.com/file/55dxp7
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

What is your solution, and what problems are you having with it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: Can any one solve this Problem