@Divya Jain: In the algorithm I gave, please note that, the *max value in
left subtree* should be *smaller than* the current node's key, which inturn
should be *smaller than* the *min value in right subtree*. That way, my
algorithm would return false for the example which you gave.
On Sun, Jul 4,
@Raj N
It won't work for the tree like. your method would return true for the
following tree.
13
/
12
\
14
On Sat, Jul 3, 2010 at 3:45 AM, Raj N rajn...@gmail.com wrote:
According to me perform inorder traversal and at every point store the
current element in a temporary
@Dheeraj: It would return false. Initially temp=12, next temp=14, then it'll
compare 13temp and flag becomes 0 and hence not bst. Am I wrong ??
On Sun, Jul 4, 2010 at 10:01 AM, Dheeraj Jain dheerajj...@gmail.com wrote:
@Raj N
It won't work for the tree like. your method would return true for
@dheeraj
for this tree inorder is 12 14 13
first 12 comes,it is saved in temp
now 14 comes since 1412 so temp =14
now when 13 comes which is less than temp hence not a bst
correct me if i wrong
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
According to me perform inorder traversal and at every point store the
current element in a temporary variable and check if the next element
obtained is greater than temp otherwise return false
int temp=-;
int flag=1;
void isBst(NODE *tree)
{
if (tree!=NULL)
{
@ above
here u r comparing node value with min and max only
for eg if ur tree is
45
/ \
65 85
/
25
ur code will say that this is bst.
http://geeksforgeeks.org/?p=3042 has all the approaches (right and wrong)
for solving this.
On Thu, Jul 1, 2010 at 4:43 AM, divya jain sweetdivya@gmail.com wrote:
@ above
here u r comparing node value with min and max only
for eg if ur tree is
45