a 1,10,12,14,16
b 5,6,9,12
c 16,19,22,25

this approch will fail


the fact that two pointers should move atleast to find minDistance is not
getting addressed completely in this solution

in this example min D = 5-1=4 to start with
then pointer in arr a moves, abs(5-10), abs(10-16) both are greater than 4
so the algo will stop

it must not stop because we donot know the nature of numbers below, hence
the stop should happen only when two array elements are exhausted

int md=MAX_INT;
int i=0; int j=0; int k=0;
while ((i<n) &&(j<n)) ||((i<n) &&(k<n)) ||((k<n) &&(j<n))
{

/*   find md between three pairs, and which ever is minimum,
find the lower element's index like 5,2,3 then mind is 3-2 and
lower number belongs to arr b, increment that index like j in this example*/

   /*int ab=abs(a[i]-b[j]) ;
   int bc= abs(b[j]-c[k]);
   int ca= abs([c[k]-a[i]);
   md= min(md, min(min(ab,bc),ca));*/ //this is boring to write...

}







Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Sat, Jun 18, 2011 at 12:37 AM, Dumanshu <duman...@gmail.com> wrote:

> @Harshal: your terminating condition would be -
> lets say we have set the pointers to index 0 of each to get the min
> distance.
> for index 0 set the min_dist overall to the max distance among the 3
> pairs. Now increase the pointer with the minimum value and check the
> max distance between pairs. If distance now is more than min_dist we
> terminate and we have the answer
> else continue incrementing the pointer with the minimum value until we
> get a distance value greater than the previously computed min_dist
> value.
> correct me if i have misinterpreted ur algo.
>
> On Jun 17, 10:08 pm, Harshal <hc4...@gmail.com> wrote:
> > I think this will work,
> > have 3 pointers p,q,r pointing last elements of the 3 lists.
> > compute the difference between each pair.
> > decrement the index of the list having the min element.
> > (at each stage, save the current indices and current max distance).
> >
> > Same logic for the min distance part, just start from index 0.
> >
> >
> >
> >
> >
> > On Fri, Jun 17, 2011 at 9:43 PM, Ashish Goel <ashg...@gmail.com> wrote:
> > > merge two and if required third  array keeping array tag with the
> elements
> > > walk over the merged list and see adjacent distance which is minimum
> with
> > > the condition that the tage of the adjacent elements are different
> >
> > > Best Regards
> > > Ashish Goel
> > > "Think positive and find fuel in failure"
> > > +919985813081
> > > +919966006652
> >
> > > On Fri, Jun 17, 2011 at 9:36 PM, Dumanshu <duman...@gmail.com> wrote:
> >
> > >> U have got 3 sorted arrays A1 A2 and A3 having m n and p elements
> > >> respectively. A gap of 3 arrays is defined to be max distance between
> > >> 3 nos if they are put on a no line say u pick three 2 12 and 7 then
> > >> the gap is 10. Now u have to find an efficient way of chosing 3 nos
> > >> from these 3 seperate arrays (A1, A2, A3) such that their gap is
> > >> minimum. Of course if a num say 2 occurs in all 3 then gap is 0!!!
> >
> > >> --
> > >> 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?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 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?hl=en.
> >
> > --
> > Harshal Choudhary,
> > III Year B.Tech CSE,
> > NIT Surathkal, Karnataka, India.- 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 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?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 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?hl=en.

Reply via email to