Re: [algogeeks] Re: Difference b/w two elements in a array

2010-07-15 Thread jalaj jaiswal

 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;in;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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%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.comalgogeeks%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.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-14 Thread vikas kumar
Thanks Amit and srikanth for pointing that out. I should have done
some analysis before posting this solution.
we can do this problem in 2 steps:
find-min-diff(arr a)
{
   sort(a)
   find(a, 0, min=INF, i=0, j=0)
   return {min, i, j}
}

find(a, index, min, i, j)
{
   if(a[index+1] - a[index]   min){
  min = a[index+1] - a[index];
  i= index, j= index+1
   }
   find(a, index+1, min, i, j)
}

run time -- sorting time + O(n)
space-- sorting complexity + O(1)

Let us discuss if we can do it without sorting the array elements.

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.

On Jul 14, 9:27 am, Ashish Goel ashg...@gmail.com wrote:
 count sort and then find mindiff

 fot (int i=1;in;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.comalgogeeks%2bunsubscr...@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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Difference b/w two elements in a array

2010-07-13 Thread Amit Mittal
Vikas,
Consider the following case
2 5 16 17 20 25;
Neither two max nor two min will give the minimum difference.


On Tue, Jul 13, 2010 at 9:52 AM, vikas kumar vikas.kumar...@gmail.comwrote:

 I did not get your point.
 for 2 6 3 7
 min 2
 sec min 3
 difference is 1
 answer is 2 and 3
 what more is asked??

 On Jul 12, 2:21 pm, srikanth sg srikanthini...@gmail.com wrote:
  2 6 3  7
  check for this
 
  On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar vikas.kumar...@gmail.com
 wrote:
 
   traverse array with 2 elements keeping track of 2 min elements. time
   O(n) space O(1)
 
   On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
Constraint - O(n)
 
On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com
 wrote:
 Given an array of size n.find 2 numbers from array whose difference
 is
 least.
 
 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 algogeeks%252bunsubscr...@googlegroups.comalgogeeks%25252bunsubscr...@googlegroups.com
 
 
 .
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
 
--
Amit Jaspal
Btech 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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%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.comalgogeeks%2bunsubscr...@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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-13 Thread Tech Id
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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Difference b/w two elements in a array

2010-07-13 Thread Ashish Goel
count sort and then find mindiff

fot (int i=1;in;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.comalgogeeks%2bunsubscr...@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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
traverse array with 2 elements keeping track of 2 min elements. time
O(n) space O(1)

On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
 Constraint - O(n)

 On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
  Given an array of size n.find 2 numbers from array whose difference is
  least.

  --
  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.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 Amit Jaspal
 Btech 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.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
traverse array with 2 elements keeping track of 2 min elements. time
O(n) space O(1)

On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
 Constraint - O(n)

 On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
  Given an array of size n.find 2 numbers from array whose difference is
  least.

  --
  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.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 Amit Jaspal
 Btech 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.



Re: [algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread srikanth sg
2 6 3  7
check for this

On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar vikas.kumar...@gmail.comwrote:

 traverse array with 2 elements keeping track of 2 min elements. time
 O(n) space O(1)

 On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
  Constraint - O(n)
 
  On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
   Given an array of size n.find 2 numbers from array whose difference is
   least.
 
   --
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Amit Jaspal
  Btech 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.comalgogeeks%2bunsubscr...@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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread ankur aggarwal
order nlogn is trivial ..
any thing better ??


On Mon, Jul 12, 2010 at 2:51 PM, srikanth sg srikanthini...@gmail.comwrote:

 2 6 3  7
 check for this


 On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar vikas.kumar...@gmail.comwrote:

 traverse array with 2 elements keeping track of 2 min elements. time
 O(n) space O(1)

 On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
  Constraint - O(n)
 
  On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
   Given an array of size n.find 2 numbers from array whose difference is
   least.
 
   --
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Amit Jaspal
  Btech 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
With Regards

Ankur Aggarwal

-- 
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.



Re: [algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread Anil C R
you can find both the smallest and the second smallest number ...
Anil


On Mon, Jul 12, 2010 at 3:21 PM, ankur aggarwal ankur.mast@gmail.comwrote:

 order nlogn is trivial ..
 any thing better ??



 On Mon, Jul 12, 2010 at 2:51 PM, srikanth sg srikanthini...@gmail.comwrote:

 2 6 3  7
 check for this


 On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar 
 vikas.kumar...@gmail.comwrote:

 traverse array with 2 elements keeping track of 2 min elements. time
 O(n) space O(1)

 On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
  Constraint - O(n)
 
  On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
   Given an array of size n.find 2 numbers from array whose difference
 is
   least.
 
   --
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Amit Jaspal
  Btech 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 With Regards

 Ankur Aggarwal

  --
 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.comalgogeeks%2bunsubscr...@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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread Anil C R
oh never mind that was wrong... :P
Anil


On Mon, Jul 12, 2010 at 5:03 PM, Anil C R cr.a...@gmail.com wrote:

 you can find both the smallest and the second smallest number ...
 Anil



 On Mon, Jul 12, 2010 at 3:21 PM, ankur aggarwal 
 ankur.mast@gmail.comwrote:

 order nlogn is trivial ..
 any thing better ??



 On Mon, Jul 12, 2010 at 2:51 PM, srikanth sg srikanthini...@gmail.comwrote:

 2 6 3  7
 check for this


 On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar 
 vikas.kumar...@gmail.comwrote:

 traverse array with 2 elements keeping track of 2 min elements. time
 O(n) space O(1)

 On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
  Constraint - O(n)
 
  On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com
 wrote:
   Given an array of size n.find 2 numbers from array whose difference
 is
   least.
 
   --
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Amit Jaspal
  Btech 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 With Regards

 Ankur Aggarwal

  --
 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.comalgogeeks%2bunsubscr...@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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread aejeet
This problem cannot be solved in less than O(nlgn) time with O(1)
space. The Element Distinctness Problem has a proven lower bound of
Omega(nlgn). If the least difference problem could be solved in O(n)
then we can reduce the ED Problem to Least Difference problem and
solve it in O(n) time. This contradicts the lower bound.
http://en.wikipedia.org/wiki/Element_distinctness_problem

We can use extra space  do counting sort but even that will not be
O(size of array) but actually O(max value in the array).



On Jul 12, 5:51 am, ankur aggarwal ankur.mast@gmail.com wrote:
 order nlogn is trivial ..
 any thing better ??

 On Mon, Jul 12, 2010 at 2:51 PM, srikanth sg srikanthini...@gmail.comwrote:



  2 6 3  7
  check for this

  On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar 
  vikas.kumar...@gmail.comwrote:

  traverse array with 2 elements keeping track of 2 min elements. time
  O(n) space O(1)

  On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
   Constraint - O(n)

   On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
Given an array of size n.find 2 numbers from array whose difference is
least.

--
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.comalgogeeks%2bunsubscr...@googlegroups.com
  algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com

.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.

   --
   Amit Jaspal
   Btech 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@googlegroups.com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 With Regards

 Ankur Aggarwal

-- 
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.



[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
I did not get your point.
for 2 6 3 7
min 2
sec min 3
difference is 1
answer is 2 and 3
what more is asked??

On Jul 12, 2:21 pm, srikanth sg srikanthini...@gmail.com wrote:
 2 6 3  7
 check for this

 On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar vikas.kumar...@gmail.comwrote:

  traverse array with 2 elements keeping track of 2 min elements. time
  O(n) space O(1)

  On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
   Constraint - O(n)

   On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
Given an array of size n.find 2 numbers from array whose difference is
least.

--
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.comalgogeeks%2bunsubscr...@googlegroups.com
  algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com

.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.

   --
   Amit Jaspal
   Btech 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.comalgogeeks%2bunsubscr...@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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.