If the range of numbers is known, sort the array using radix sort and compare difference of adjacent elements.
On Sep 2, 2:33 pm, Varun S V <varun...@gmail.com> wrote: > Sorry this doesnt work. The difference between any other two sets can be > lesser than the difference between two min numbers. > > On Wed, Sep 2, 2009 at 2:57 PM, Varun S V <varun...@gmail.com> wrote: > > > Since we difference between two minumum elements should suffice, how about > > finding the min and second minimum element in the array in single scan and > > returning their difference. This should take not more than O(N) time. > > > Regards, > > -Varun. > > > On Wed, Sep 2, 2009 at 12:09 AM, Shishir Mittal > > <1987.shis...@gmail.com>wrote: > > >> Sort the array and find the minimum of difference of adjacent values of > >> the sorted array. > >> Time Complexity : O(nlogn), Space Complexity : O(1) > > >> On Tue, Sep 1, 2009 at 6:35 PM, ankur aggarwal > >> <ankur.mast....@gmail.com>wrote: > > >>> given a array of length n. find 2 number such that their differnce is > >>> minimum..... > > >> -- > >> Shishir Mittal > >> Ph: +91 9936 180 121 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---