Java temporal and spatial complexity

1

I made the following code under some specifications in a project that I am doing, however I must calculate the temporal and spatial complexity and I do not know how much in each case for these recurrences. It would be very helpful if someone can help me.

    public class ProblemaA
    {
      public static void main(String[]  args)
       {
        try(BufferedReader br = new BufferedReader(new 
            InputStreamReader(System.in)))
         {
           String str = br.readLine();
           while(str != null && !str.equals(""))
             {
               String[] val = str.split(" ");
               int n = Integer.parseInt(val[0]);
               double a = Double.parseDouble(val[1]);
               double b = Double.parseDouble(val[2]);
               double c = Double.parseDouble(val[3]);
               double d = Double.parseDouble(val[4]);

               String res = new String();
               DecimalFormat df = new DecimalFormat("#.0000");
               double r = 0.00;
               if(n==0)
                {
                  r=a;
                }
               else if(n==1)
                {
                 r=b;
                }
               else
                {
                  for (int i = 0; i <= n; i++) 
                  {
                    r += problemaA(i,a,b,c,d)*problemaA(n-i,a,b,c,d);
                  }
                }
            res  = df.format(r);
            System.out.println(res);
            str=br.readLine();
        }


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
private static double problemaA(int n, double a, double b, double c, double d) 
{
    double res= 0.00;

        if(n == 0)
        {
            res = a;
        }
        else if(n == 1)
        {
            res = b;
        }
        else 
        {
            res = c*problemaA(n-2, a, b, c, d) + d*problemaA(n-1, a, b, c, d);
        }   
    return res;
}
    
asked by Yesid Bejarano Camacho 11.12.2017 в 01:53
source

0 answers