Re: [algogeeks] kth largest element in two sorted arrays

2012-01-30 Thread atul anand
to find kth largest element in the 2 sorted array can be done by simple
merge...
obv no need for extra space...two indexes will do.

you just need to check arr1[i...n] == arr2[j..m]

if(arr1[i]  arr2[j])
{
   cnt++;
   index=arr2[j];
   j++;

}
else
{
 cnt++;
 index=arr1[i];
 i++;

}

if(k==cnt)
{
  print  kthe largest element is at position arr[index]
break;
}



On Tue, Jan 31, 2012 at 1:15 AM, Ashish Goel ashg...@gmail.com wrote:

 Hi,

 I am trying to write code for this problem but having issues.
 Can you help

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

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



Re: [algogeeks] kth largest element in two sorted arrays

2012-01-30 Thread Ashish Goel
i think this can be done much faster similar to findling median of two
sorted arrays by proceeding with comparing medians of two arrays and then
reducing the data set to approx 3/4th of 2n. I am looking for that algo if
osmeone have.

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


On Tue, Jan 31, 2012 at 9:26 AM, atul anand atul.87fri...@gmail.com wrote:

 to find kth largest element in the 2 sorted array can be done by simple
 merge...
 obv no need for extra space...two indexes will do.

 you just need to check arr1[i...n] == arr2[j..m]

 if(arr1[i]  arr2[j])
 {
cnt++;
index=arr2[j];
j++;

 }
 else
 {
  cnt++;
  index=arr1[i];
  i++;

 }

 if(k==cnt)
 {
   print  kthe largest element is at position arr[index]
 break;
 }



 On Tue, Jan 31, 2012 at 1:15 AM, Ashish Goel ashg...@gmail.com wrote:

 Hi,

 I am trying to write code for this problem but having issues.
 Can you help

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

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


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