May be this helps
http://ds-gyan.blogspot.com/2009/12/two-numbers-with-minimum-difference.html
On Sep 28, 10:28 am, "coolfrog$"
wrote:
> @ 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.
>
@ 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
Hi Friends
This is an interesting problem and request you all to give a brief
intro to your code before putting the code. Or you may just mention
the under lying concept in the code. This will be of great help and
others will find it more ready to improve by adding there approach.
Coming back to
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
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
You are solving the wrong problem. The problem is not asking for the
difference between the two minimum elements, but for the minimum
difference between any pair of elements. In the case
int array[10]={99,35,45,33,88,9098,112,33455,678,3};
the minimum difference is |35-33| = 2.
Dave
On Sep
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
I got the problem statement wrong.
For a input of 7,8,5,1,3,4 the answer should be 1 due to the
difference between 3 and 4 or 7 and 8 or 4 and 5.
Rather than 2 due to difference between 1 and 3
Sorry every one :-(
--
You received this message because you are subscribed to the Google Groups
"A
check for this input {7,8,5,1,3,4}
On Sep 23, 10:36 pm, Rishi Agrawal wrote:
> @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
>
@Rishi: Try it on the original data with a[1] changed from 12 to 35:
int array[10]={99,35,45,33,88,9098,112,33455,678,3};
What do you get as a result?
Dave
On Sep 23, 12:36 pm, Rishi Agrawal wrote:
> @Dave, I check for the values you suggested but the code worked fine. There
> were other e
@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;
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 wrote:
> i dont think there exists a o(n) solution for this
> the best
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
@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 wrote:
> 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)
> {
>
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.
try for this {100,6,101,11}
On Sep 23, 7:40 pm, Nishant Agarwal
wrote:
> int minDiff(int arr[], int arr_size)
> {
> int min_diff = arr[1] - arr[0];
> int max_element = arr[0];
> int i;
> for(i = 1; i < arr_size; i++)
> {
> if(arr[i] - max_element < min_diff)
> min_diff = arr[i
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
> "
can anyone post this answer pls??
--
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
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
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
Trying to put down a method, I think would work ( with a small running
example )
//! Assuming non--negative numbers and difference is MOD of difference
of numbers
Let array be A[1..n]//! e.g. { 11 , 6 , 17 , 9 ]
Start with pari ( A[1], A[2] ) and difference be D = | A[1] - A[2]
|/// A[1]
21 matches
Mail list logo