Chonku, you can do that only when you have the links to parent nodes. I couldn't come up with a way of doing what you said on a basic BST(nodes having pointers only to their 2 children) that is why I suggested using an array. It doesn't change the overall complexity but if you have an idea about how implement your idea on a basic BST, I would like to hear it.
Thanks, Seckin On Fri, Aug 6, 2010 at 2:56 AM, sharad kumar <aryansmit3...@gmail.com>wrote: > do the inorder traversal of the bst ...this gives the sorted array...... > from that use > > int i=0,j=length(array) > while(i<j) > { > if(array[i]+array[j]>sum) > --j; > else if(array[i]+array[j]<sum) > ++i; > else if((array[i]+array[j])==sum) > return i,j > else > ++i,--j; > } > > > On Fri, Aug 6, 2010 at 3:10 PM, Chonku <cho...@gmail.com> wrote: > >> Two inorders would achieve the same thing without using an array. One >> pointer running inorder with LDR and other pointer running inorder with RDL. >> Compare the sum at the two nodes and then adjust them accordingly. >> >> On Fri, Aug 6, 2010 at 2:11 PM, Manjunath Manohar < >> manjunath.n...@gmail.com> wrote: >> >>> the solution elegant..but is there any on the fly method by just >>> exploiting the BST property....by using left and right pointers >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Algorithm Geeks" group. >>> To post to this group, send email to algoge...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > yezhu malai vaasa venkataramana Govinda Govinda > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@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.