Search All Articles Submit your Website or Blog to A New Internet Library
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.
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.


2 comments:
did u get the answer for it?
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.