@Dheeraj: It would return false. Initially temp=12, next temp=14, then it'll compare 13<temp and flag becomes 0 and hence not bst. Am I wrong ??
On Sun, Jul 4, 2010 at 10:01 AM, Dheeraj Jain <[email protected]> wrote: > @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 <[email protected]> wrote: > >> 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=-9999; >> int flag=1; >> void isBst(NODE *tree) >> { >> if (tree!=NULL) >> { >> isBst(tree->left); >> if (temp<tree->info) >> temp=tree->info; >> else >> { >> flag=0; >> return; >> } >> isBst(tree->right); >> } >> } >> >> Please correct me if I'm wrong >> >> >> On Fri, Jul 2, 2010 at 6:43 PM, sharad kumar <[email protected]>wrote: >> >>> i read that link ,i dont think that is very efficient,someone plzzz look >>> at that soln n comment >>> bcoz i m really confused in this isbst ques so plzzz >>> >>> -- >>> 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]<algogeeks%[email protected]> >>> . >>> 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 [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<algogeeks%[email protected]> >> . >> 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > 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 [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.
