Your comment brings to mind that we could do an O(n) sort such as a Radix Sort. Any ordinary implementation will be O(n) as a fixed number of passes will be required based on the word size.
Dave On Sep 23, 11:21 am, nishaanth <nishaant...@gmail.com> wrote: > i dont think there exists a o(n) solution for this > the best we can do is sort in o(nlogn) and then do a o(n) traversal > > > > > > On Thu, Sep 23, 2010 at 8:48 PM, Dave <dave_and_da...@juno.com> wrote: > > @Yellow: Change the 12 in a[1] in your test case to 35 and see what > > you get. > > > Dave > > > On Sep 23, 10:09 am, Yellow Sapphire <pukhraj7...@gmail.com> wrote: > > > I hope this will work. It finds the two minimum numbers and then prints > > the > > > difference. > > > > #include <stdio.h> > > > #include <stdlib.h> > > > void find_two_mins(int array[], int size) > > > { > > > int i,t; > > > int min1=array[0], min2=array[1]; > > > for (i=2; i<size; i++){ > > > t=array[i]; > > > if(t<=min1) { > > > min2=min1; > > > min1=t; > > > continue; > > > } > > > } > > > printf("\nMin elements are 1: %d 2: %d", min1,min2); > > > printf("\n Absolute difference between two minimum elements are %d", > > > abs(min1-min2)); > > > > } > > > > int main() > > > { > > > //int array[10]={ 9,2,3,4,1,7,5,6,8,0}; > > > // > > > int array[10]={99,12,45,33,88,9098,112,33455,678,3}; > > > find_two_mins(array,10); > > > return 0; > > > > }- Hide quoted text - > > > > - Show quoted text - > > > -- > > 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. > > -- > S.Nishaanth, > Computer Science and engineering, > IIT Madras.- Hide quoted text - > > - Show quoted text - -- 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.