Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-28 Thread coolfrog$
@ sorurav yes , the basic logic is required so that the code can be understood in single Run.. i also request the same to all dear friends. Regards.. On Tue, Sep 28, 2010 at 8:11 PM, sourav wrote: > Hi Friends > > This is an interesting problem and request you all to give a brief > i

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-27 Thread rahul
If their is no constrain on assumptions. 1.Sort the array. 2. check the dif between 2 elements. { 99,35,45,33,88,9098,112,33455,678,3} sorted arrary : { } would be something. now update the min_diff. another example : { 7,8,1,3,5,4} sorted arrary : { 1,3,4,5,7,8} min diff is 1. Please correct

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-27 Thread satish
step1>construct heap using siftdown. // time complexity wil be O(n) and space complexity O(1). step2>take mindifference=a[1]. step3>for i=1 ,i<=n/2 do { find the difference of (root,root-left),(root,root->right)and (root->left,root->right).and maintain mindifference is the smallest d

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-24 Thread Rishi Agrawal
Printing the Array: 99 35 45 33 88 9098 112 33455 678 3 Min elements are 1: 3 2: 33 Absolute difference between two minimum elements are 30 On Fri, Sep 24, 2010 at 9:39 AM, Dave wrote: > @Rishi: Try it on the original data with a[1] changed from 12 to 35: > >int array[10]={99,3

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-23 Thread Rishi Agrawal
@Dave, I check for the values you suggested but the code worked fine. There were other errors in the code. I have rectified them now. The following code seems to be working fine and in O(n) time. #include #include void find_two_mins(int array[], int size) { int i,t; int min1, min2;

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-23 Thread nishaanth
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 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

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-23 Thread Yellow Sapphire
I hope this will work. It finds the two minimum numbers and then prints the difference. #include #include void find_two_mins(int array[], int size) { int i,t; int min1=array[0], min2=array[1]; for (i=2; ihttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-23 Thread Soundar
Modeling Expert 's code is greedyit won't work for the test cases in which the optimal answer is does not lie between first two numbers.. On 9/23/10, Srinivas wrote: > can anyone post this answer pls?? > > -- > You received this message because you are subscribed to the Google Groups > "

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-21 Thread LG JAYARAM .
Guyswe need to find two numbers in a array with minimum difference ah On Tue, Sep 21, 2010 at 8:52 PM, Rahul Singal wrote: > try running it on [ 11 , 6 , 100, 101] > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to

Re: [algogeeks] Re: do this: two numbers with min diff

2010-09-21 Thread Rahul Singal
try running it on [ 11 , 6 , 100, 101] -- 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