First find the bigOh running time of inside in terms of inpu

First, find the big-Oh running time of inside, in terms of input sizes n_a and n_b. private static double[] inside(double[] a, double[] b) {double[] c = new double[a. length]; int i = 0, j = 0; for (int k = 0; k: c. length; k++) {if (i

Solution

private static double[] inside(double[] a,double[] b)//sizes of na and nb of lists
{
   double[] c=new double[a.length];//1 unit time
   int i=0,j=0;   //1 unit time
   for(int k=0;k<c.length;k++)   //na times
   {
       if(i<a.length){               //na times
           if(j<b.length){           //na times  
               if(a[i]<=b[j])       //na time extreme for all(upper bound)
                   c[k]=a[i];   //na time
               else
                   c[k]=b[j];   //na time
           }else
           {
               c[k]=a[i];       //na time
               i++;           //na time
           }
       }else {
           if(j<b.length){           //na time
               c[k]=b[j];       // na time
               j++;           // na time
           }
       }
   }
   return c;   //1 unit
}

the bid-Oh running time of inside method is
=>11na+3
=>O(na) //(in upper bound time complexity constants will be negligible)

for outside method running time is

public static double[] outside(double[] list)
{
   int x=list.length;   //1 unit
   if(x<=1) return list;   //1 unit
   double[] a=new double[x/2];   //1 unit
   double[] b=new double[x-x/2];   //1 unit
   for(int i=0;i<a.length;i++)   // n/2 unit
   {
       a[i]=list[i];       //n/2
   }
   for(int i=0;i<b.length;i++)   //n/2
   {
       b[i]=list[i+x/2];   //n/2
   }
   return outside(inside(a,b));   //na log n
}

the total running time of outer method is
=>4(n/2)+4+nalog(n)
=>O(nalog(n))

 First, find the big-Oh running time of inside, in terms of input sizes n_a and n_b. private static double[] inside(double[] a, double[] b) {double[] c = new do

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site