> > I have one more question here , suppose we have some dynamic array >> ( of const size ) where insertions and removal is happening >> dynamically ---> >> you want the 2 elements from the array having least difference. Design >> a data structure for this. Less than O(n) solution appreciated. >> > i have a nlogn solution for it... as the insertion and deletion is happening dynamically... thinkin of O(n) is ...a bit tedious i think
> > On Jul 14, 9:27 am, Ashish Goel <ashg...@gmail.com> wrote: > > count sort and then find mindiff > > > > fot (int i=1;i<n;i++) > > if (a[i]-a[i-1] <mindiff) { mindiff =a[i]-a[i-1]; ele1=a[i-1]; > ele2=a[i];} > > > > Best Regards > > Ashish Goel > > "Think positive and find fuel in failure" > > +919985813081 > > +919966006652 > > > > On Tue, Jul 13, 2010 at 2:47 PM, Tech Id <tech.login....@gmail.com> > wrote: > > > Construct a BST for the array - O(nlogn) > > > Traverse the tree and find a node which has > > > minimum difference with either its left or > > > right child in whole of the tree. > > > (Because the required numbers have to be > > > adjacent to each other in a sorted array). - O(n) > > > > > => Total order:O(nlogn) > > > > > -- > > > 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> > <algogeeks%2bunsubscr...@googlegroups.com<algogeeks%252bunsubscr...@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. > > -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- 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.