Question

In: Computer Science

   * Add operation counts    * f(N) formula (show your work)    * O(N) reduction...


   * Add operation counts
   * f(N) formula (show your work)
   * O(N) reduction
   */
   public static long sum3(int N)//f(N) = ; O(N) =
   {
       long opCount = 0;
       long sum = 0;
       for(int i = 0; i < N; i++)
       {
           for(int j = 0; j < N*N; j++)
           {
               sum++;
           }
       }
       System.out.println("f(N) = [your answer]");
       System.out.println("O(N) = [your answer]");
       System.out.println("OpCount : "+opCount);
       return sum;

Solutions

Expert Solution

        public static long sum3(int N)// f(N) = ; O(N) =
        {
                long opCount = 0;
                long sum = 0;
                for (int i = 0; i < N; i++)
                {
                        for (int j = 0; j < N * N; j++)
                        {
                                opCount++;
                                sum++;
                        }
                }
                
                /*
                 * The Outer loop runs N times.. For each outer loop, the
                 * inner loop is run N^2 times.. Hence total opCount 
                 * will be N^3.
                 * 
                 * Hence f(n) = n^3
                 * O(N) = O(N^3)
                 */

                System.out.println("f(N) = " + (N * N * N));
                System.out.println("O(N) = " + (N*N*N));
                System.out.println("OpCount : " + opCount);

                return sum;

        }
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

* Add operation counts -    * f(N) formula (show your work) -    * O(N)...
* Add operation counts -    * f(N) formula (show your work) -    * O(N) reduction -    */    public static long sum4(int N)//f(N) = ; O(N) =    {        long opCount = 0;        long sum = 0; // 1        for(int i = 0; i < N; i++)        {            for(int j = 0; j < i; j++)            {                sum++;   ...
Does this look correct? Add operation counts - 0.5pt    * f(N) formula (show your work)...
Does this look correct? Add operation counts - 0.5pt    * f(N) formula (show your work) - 0.5pt    * O(N) reduction - 0.5pt public static long sum1(int N)//f(N) = ; O(N) =    {        long opCount = 0;        long sum = 0; //1        opCount++;        opCount++;        opCount++;        for(int i = 0; i < N; i++) //2 + 2N        {            sum++; //N       ...
Correctly follow the described algorithm to complete the method    * Add operation counts -   ...
Correctly follow the described algorithm to complete the method    * Add operation counts -    * f(N) formula (show your work) -    * O(N) reduction -    */    public static int[] algorithm1(int N)//f(N) = ; O(N) =    {        long opCount = 0;        int[] arr = new int[N];        /*        * Use the following method to fill the array        * For each position in the array, generate a...
If f(n) = 3n+2 and g(n) = n, then Prove that f(n) = O (g(n))
If f(n) = 3n+2 and g(n) = n, then Prove that f(n) = O (g(n))
Use Excel to show your work and include the formula in the cell to show how...
Use Excel to show your work and include the formula in the cell to show how you arrived at your figures. Round percentages (example if 49.2, round to 49). Background: ABC, Inc., produces widgets. The company manufactures three levels of widgets-Economy, Better and Best. Selected information on the widgets is given below. Economy Better Best Selling price per widget $40.00 $60.00 $90.00 Variable expense per widget production $22.00 $27.00 $31.50 Selling (5% of selling price) $2.00 $3.00 $4.50 All sales...
Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 +...
Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 + n)(n ^2 + π/2 ) 3. 1 + 2 + 3 + · · · + n − 1 + n
Please show all your work step by step and all the formula that is used. This...
Please show all your work step by step and all the formula that is used. This is my 3rd time posting as people do not explain what they are doing. Therefore, do not answer if you can't explain. D. What is the present value (PV) of a 12-years lease arrangement with an interest rate of 7.5% that requires annual payments of $4250. Per year with first payment being due now? E. A recent college graduate hopes to have $200000. Saved...
Answer & show work andswer and show work answer n show work Using a sample of...
Answer & show work andswer and show work answer n show work Using a sample of 20 people, the testing agency found that 14 of them had better protection than that provided by the competitor. Do you have enough evidence to say/claom that your suncreen lotion provides better protection than the competitiors in a majority of cases? Use alpha = 0.01 to answer. 1. What are the apporiate hypotheses for situation? 2. the appropriate rejection rule is? 3. the calculated...
Prove why f(n)=big omega(g(n)) then f(n)=o(g(n)) is NEVER TRUE. Prove why f(n) +g(n) =Theta(max(f(n),g(n)) is ALWAYS...
Prove why f(n)=big omega(g(n)) then f(n)=o(g(n)) is NEVER TRUE. Prove why f(n) +g(n) =Theta(max(f(n),g(n)) is ALWAYS TRUE
For the given array, simulate the working operation of Bubble Sort. Show your work at each...
For the given array, simulate the working operation of Bubble Sort. Show your work at each step. Make sure to show the status of the array after every swap. [ 28, 13, 22, 7, 34, 2 ]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT