Question

In Java code provide the desired Big O notation methods and then call those methods in...

In Java code provide the desired Big O notation methods and then call those methods in the main.

Problem: Let n be the length of an integer array a, for each of the following classes

?(log(log(log(?))))

?([log(?)] 3 )

?(? 5 )

?(4 ? )

?(?!)

?(? ? )

write a method that takes as sole input an array a of length n, non-recursive, whose running time belongs to only one of the above classes.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The complexity of loops is equal to the number of time the innermost loop is executed. So O(n n) is basically equal to

A simple program for it:


import java.util.Scanner;
public class E
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.print("Enter no. of elements you want in array:(row n col)");
int row = s.nextInt();
int col = s.nextInt();
       int a[][] = new int[row][col];
System.out.println("Enter all the elements:");
for(int i = 0; i < row; i++)
{
           for(int j = 0; j<col;j++)
           {
               a[i][j] = s.nextInt();
           }
}
for(int i = 0; i < row; i++)
{
           for(int j = 0; j<col;j++)
           {
               System.out.print(a[i][j]+"\t");
           }
           System.out.println("\n");
}
}
}

To check the time complexity :

the no of times loop of row(I) will be executed= n(equal to no row rows)

no of times loop for col will be executed= n*n(equal for no of rows * no of cols)

so overall time complexity will be the one of the inner loop which is n*n = O(n*n)=

Add a comment
Know the answer?
Add Answer to:
In Java code provide the desired Big O notation methods and then call those methods in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running...

    In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n) for(int i=n-1; i >=0; i--){ for(int k=0; k < i*n; k++){ // do something that takes O(1) time } }

  • Write an application with two classes USING JAVA METHODS HAVE TO BE CREATED USING RECURSION. First...

    Write an application with two classes USING JAVA METHODS HAVE TO BE CREATED USING RECURSION. First class named Recursion has the following three recursive methods: // PRECONDITION n is positive integer. Method sumTerms returns sum of terms that are // reciprocal values of first n integers, with  alternating signs.      // For example,  sumTerms(7) returns  the following:  1/1 – 1/2  + 1/3 – 1/4  + 1/5 -1/6 + 1/7. // Terms with an odd denominator have positive sign, and terms with even denominator have // negative sign.  ...

  • Provide the Big‐O notation for the following lines of Java code, make sure you include all...

    Provide the Big‐O notation for the following lines of Java code, make sure you include all the necessary steps to reach your answer to receive any credit: a. for (i = 10; i < n – 8; i++) { for( j = 1; j < m; j *= 2) x = i + j; } b. for(k = 0; k <= m; k += 2) { l = 0; while(l < n/2) { y = l * 4 – x;...

  • In Java All methods listed below must be public and static. If your code is using...

    In Java All methods listed below must be public and static. If your code is using a loop to modify or create a string, you need to use the StringBuilder class from the API. Keep the loops simple but also efficient. Remember that you want each loop to do only one "task" while also avoiding unnecessary traversals of the data. No additional methods are needed. However, you may write additional private helper methods, but you still need to have efficient...

  • This is java. Please let me know about those code. Please do not use array and...

    This is java. Please let me know about those code. Please do not use array and scanner. Just do by loop. // a) Task: Find the sum of all multiples of 3 and 5 less than 1000. // b) Task: Given two integers k and n, print out every multiple of k less than n // c) Task: Given an integer n, print out k^k for every k=1...n // d) Task: Write a function called "factorProduct" that takes as input...

  • by netBeans C++ java by netBeans C++ java by netBeans C++ java 1. Answer the following...

    by netBeans C++ java by netBeans C++ java by netBeans C++ java 1. Answer the following question a) (4 marks) Write a Java method, which takes an integer array and two integers x and y as input parameters. The method should exchange the value in position x with the value in the position y in the array. Example: If x = 1, y=2 Input Array Output Array b) (4 marks) Write the main method to do the following: 1. Define...

  • Write a JAVA program with methods that initializes an array with 20 random integers between 1...

    Write a JAVA program with methods that initializes an array with 20 random integers between 1 and 50 and then prints four lines of output, containing 1)The initialized array. 2)Every element at an even index. 3)Every even element. 4)All elements in reverse order. Requirements (and hints): 1. Build a method that takes any integer array as input and prints the elements of the array. ALL printing in this lab must be done using a call to the printArray method and...

  • In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this...

    In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this solution. Write a program that reads an integer and displays, using asterisks, a filled and hollow square, placed next to each other. For example, if the side length is 5. the program should display: ***** ***** You can assume that the user will enter a side length that is at least 2. If user enters a number smaller than 2, and your program has...

  • Call stack question! Long one... The call stack is part of main memory that is reserved...

    Call stack question! Long one... The call stack is part of main memory that is reserved for function calling. Like all r memory it is finite, so can be exhausted resulting in a stack overflow. Recursive functions allocate space on the stack for each recursive call: if there are many such recursive calls a stack overflow can result. The questions that follow ask you to investigate recursive functions and stack overflows. Note that when running programs in the Linux terminal...

  • Create a Java code that includes all the methods from the Lecture slides following the ADTs...

    Create a Java code that includes all the methods from the Lecture slides following the ADTs LECTURE SLIDES Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT