↑ Grab this Headline Animator

Monday, June 30, 2008

Can any one solve this Puzzle / Problem in C#.NET

public class Tree
public int GetNodeCount(Node n)

public Node GetLeastCommonAncenstor (Node m, Node n)



public class Node
Node m_Left;
Node m_Right;

String m_Word;
1.Implement public int GetNodeCount(Node n) such that it returns the number of nodes beneath (and including) the given node n.
2.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.
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.

Post your solution in the comments section.

Submit this story to DotNetKicks


Anonymous said...

did u get the answer for it?

John Hamm said...

Staying in the scope of your example, there is no way to get the parent node of a or b, and there is no way to start at the root node of the tree. Therefore, there's no solution based on the scope of your example.

Post a Comment

Post your comments/questions/feedback for this Article.


Latest Articles