Basically the index of ( a + b) in the final array will be ceil(( index of a + index of b )/2). Also if there is a clash of indices you just have to compare the values at those indices and adjust them. I have run my concept with below two arrays and it works !!!
Arary A: 1 2 3 4 5 6 Array B: 2 3 5 6 8 9 addition of indices 8 4 5 11 6 11 addition of values (2+9) ( 1+5) (4+2) (6+8) ( 3+3) ( 5 + 9) values: 11 6 6 14 9 14 Added indices: 4 5 6 8 11 11 ( These are not sorted indices, you will know the indices of values in the final array right away after looking at the indices of a and b ) indices/2: 2 3 3 4 6 6 corresponding final values 6 6 6 11 14 14 - Kishen Das On Fri, Apr 30, 2010 at 7:05 AM, divya <sweetdivya....@gmail.com> wrote: > Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's > say they are decreasingly sorted), we define a set S = {(a,b) | a \in > A > and b \in B}. Obviously there are n^2 elements in S. The value of such > a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs > from S with largest values. The tricky part is that we need an O(n) > algorithm. > > -- > 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. > > -- 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.