In: Computer Science
* 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;
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.