Inorder traversal of the BST will give elements in sorted way. Let us
assume that the sorted elements are in an array A of length N.
set i=1;
while i <N-1
{
if a[i] > k, then output: "No such node"
else if(a[i]==k)
{
if (a[i+1] ==0)
output: "Two nodes found" BREAK;
else
output: "No such node." BREAK.
}
else if(a[i] <k )
{
if(a[i]+a[i+1]==k)
output: "Two nodes found" BREAK.
else if(a[i]+a[i+1] >k)
output: "No such node" BREAK
else if(a[i] +a[i+1] < k)
i++ ;
}
}//End of while-loop.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.