Yes, you are right. How about this:
bool isBST(root *t, int min=minint, int max=maxint) { return !t || ((t->value >= min) && (t->value <= max) && isBst(t->left, min, t->value) && isBst(t->right, t->value, max)); } On Nov 5, 11:04 pm, atul anand <atul.87fri...@gmail.com> wrote: > @Don : your algo wont work for following tree :- > > 30 > / \ > 20 31 > / \ > 9 41 > > above tree is not a BST bcozz here 41 should lie on the right side of the > 30....but it is not. > so we need to keep track of max and min as we move left or right part of > the tree.and each node should lie b/w that min and max range. > for more details :http://www.geeksforgeeks.org/archives/3042 > > @shady : yes correct..you can do in that way. > > > > > > > > On Tue, Nov 6, 2012 at 1:18 AM, Don <dondod...@gmail.com> wrote: > > That would work. But a simpler approach is: > > > bool isBinTree(root *t) > > { > > return (!t) || ((!t->left || (t->value > t->left->value)) && > > (!t->right || (t->value < t->right->value)) && > > isBinTree(t->left) && isBinTree(t->right)); > > } > > > On Nov 5, 2:04 pm, shady <sinv...@gmail.com> wrote: > > > Hi, > > > Can we check this by just doing an inorder traversal, and then checking > > if > > > it is in increasing order or not ? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algogeeks@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.