0
    void some_function() {
     int d[] = new int[10];
     int e[] = new int[15]; 
     int f[] = new int[20];
     int g[] = new int[25]; 
     int h[] = new int[30];
     int i[] = new int[35];
     int j[] = new int[40];
     int k[] = new int[45];
     int l[] = new int[50];
     int m[] = new int[55];
     int n[] = new int[60];
     int o[] = new int[65];
     int p[] = new int[70];
     int q[] = new int[75];
     int r[] = new int[80];
     int s[] = new int[85];
     int t[] = new int[90];
     int u[] = new int[95];
     int v[] = new int[100];
    //Randomly generate int elements of the array
     int master_list[][] = {d, e, f, g, h, i, j, k, l, m, n, 
        o, p, q, r, s, t, u, v};
     Random gen = new Random();
     int i_array[];
     double run_times[][] = new double[19][6];
     double start, end, total_time_1, total_time_2, total_time_3;
     double comp_1, comp_2, comp_3;
     for(int idex = 0; idex < master_list.length; idex++) {
        i_array = master_list[idex];
        //Randomly generate integers to put in each array        
        for(int jdex = 0; jdex < master_list[idex].length; jdex++) {
           i_array[jdex] = gen.nextInt(10);
        }

        comp_1 = ((14*(Math.pow(i_array.length, 2))) 
           + (i_array.length/2) + 4);
        comp_2 = ((14*i_array.length) + 35);
        comp_3 = ((19*i_array.length) + 4);
        /* This is the part where we begin to print and calculate
           data for our report. It begins with caluculating the
            run time of each algorithm by calling the system clock
            method of System.nanoTime() */
        System.out.println("Input size: " + i_array.length);
        System.out.println("Run time of Algorithm 1:");        
        start = System.nanoTime();
        driver.algorithm_1(i_array); 
        end = System.nanoTime();
        total_time_1 = end - start;
        System.out.println("Total time elapsed: " + total_time_1
           + " milliseconds.");
        //We then add this time into the [19][6] matrix.
        run_times[idex][0] = total_time_1;
        run_times[idex][3] = comp_1;

        //The process then repeats for algorithm 2
        System.out.println("Run time of Algorithm 2:"); 
        start = System.nanoTime();
        driver.algorithm_2(i_array); 
        end = System.nanoTime();
        total_time_2 = end - start;
        System.out.println("Total time elapsed: " + total_time_2
           + " milliseconds.");
        run_times[idex][1] = total_time_2; 
        run_times[idex][4] = comp_2; 

        //Yet again another repitition for algorithm 3
        System.out.println("Run time of Algorithm 3:");
        start = System.nanoTime();
        driver.algorithm_3(i_array); 
        end = System.nanoTime();
        total_time_3 = end - start;
        System.out.println("Total time elapsed: " + total_time_3
           + " milliseconds.\n");
        run_times[idex][2] = total_time_3;
        run_times[idex][5] = comp_3;
     }
  }

したがって、この全体の問題は、サイズが run_times[19][6] の配列を作成しようとしているということですが、サイズが [10][5] のリストしか取得できません。

したがって、アルゴリズムは int 配列 d - v を取り、それらのランダムな要素を生成しています。次に、各アルゴリズムの実行時間と複雑さを計算しています (含まれていません)。

実行時の配列は次のようなものです。 ] = algorithm_2 の複雑さ [0][5] = algorithm_3 の複雑さ

複雑さの倍数は、T(n) 再帰関係で n の配列サイズを差し込んでいます。

何が問題なのですか?コンパイルされ、実行時エラーはありません。

4

0 に答える 0