@rohit : else return (check(tree->left) || check(tree->right)); should be else
return (check(tree->left) && check(tree->right));
             we need both the left and the right to be true .
On Wed, Aug 31, 2011 at 4:18 PM, rohit <raman.u...@gmail.com> wrote:

> Q1.
>
> NODE* head //points to the bst(if it exists)
>
> void exist_bst(NODE *tree)
> {
> if(tree != NULL)
> {
>     if(tree->left->info < tree->info  && tree->right->info >= tree->info)
>     {
>        if(check(tree))
>        head = tree;
>     }
>     else
>     {
>      exist_bst(tree->left);
>      exist_bst(tree->right);
>     }
> }
> }
>
> int check(NODE *root)
> {
> if(root->left == NULL && root->right == NULL)
> return TRUE;
>
> if(tree->left->info >= tree->info  || tree->right->info < tree->info)
> return FALSE;
>
> else return (check(tree->left) || check(tree->right));
>
> }
>
> I havn't run this on system and this code is subject to more optimisation.
> This was just to give you a fair idea
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/0YV_4hilHhkJ.
>
> 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.

Reply via email to