Note that there are some explanatory texts on larger screens.

plurals
  1. POquestion about median of two array
    primarykey
    data
    text
    <p>here is pseudo code on algorithm to find median of two array</p> <pre><code>T WO -A RRAY-M EDIAN (X, Y ) n ← length[X] £ n also equals length[Y ] median ← F IND -M EDIAN (X, Y, n, 1, n) if median = NOT- FOUND then median ← F IND -M EDIAN (Y, X, n, 1, n) return median F IND -M EDIAN ( A, B, n, low, high) if low &gt; high then return NOT- FOUND else k ← (low + high)/2 if k = n and A[n] ≤ B[1] then return A[n] elseif k &lt; n and B[n − k] ≤ A[k] ≤ B[n − k + 1] then return A[k] elseif A[k] &gt; B[n − k + 1] then return F IND -M EDIAN ( A, B, n, low, k − 1) else return F IND -M EDIAN ( A, B, n, k + 1, high) </code></pre> <p>it is from introduction of algorithms MIT </p> <p>and here is my code please if something is wrong in my code tell me </p> <pre><code> public class findmedian{ public static int find(int []x,int []y){ int median; int n=x.length; median=Median( x, y, n,0, n); if ( median&lt;-100000){ Median(y,x, n,1, n); } return median; } public static void main(String[]args){ int x[]=new int[]{3,5,7,8,5,9,10}; int y[]=new int[]{12,4,8,9,6,7,10}; find(x,y); } public static int Median(int []a,int []b,int n,int low,int high) { if ( low&gt;high) return -1 ; int k=(low+high)/2; if (k==n &amp;&amp; a[n]&lt;=b[1]) return a[n]; else if ( k&lt;n &amp;&amp; b[n-k]&lt;=a[k] &amp;&amp; b[n-k]&lt;=b[n-k+1]) return a[k]; else if ( a[k]&gt; b[n-k-1]) return Median( a,b,n,low,k-1); return Median(a,b,n,k+1,high); } } </code></pre> <p>after compile it does not return anything please help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload