Question: 1 . Consider the following code and determine how many times Grape will be printed to the console. For this problem, also state what the

1. Consider the following code and determine how many times "Grape" will be printed to the console. For this problem, also state what the value of f(n) is. Your solution should be written as O(some function)= true running time, where you need to specify the function for g(n) and the true running time for f(n).
for (int i =0; i <25* n +5; i ++){
System . out . println (" Grape ") ;
}
for (int i =0; i <30* n ; i ++){
System . out . println (" Grape ") ;
}
2. Consider the equation f(n)=123n and g(n)= n2.Suppose we randomly picked c =15. What is the smallest n0(where n0>0) such that n >= n0,0<= f(n)<= cg(n).
State your solution clearly.
3. What does n represent in the definition for O() notation?
4. Consider the following code and determine how many times "Grape" will
be printed to the console. The solution should be stated in O() notation.
for (int i =0; i < n ; i ++){
for (int k =0; k < n * n ; k ++){
System . out . println (" Grape ") ;
}
}
5. Demonstrate the output for the following code and state the asymptotic complexity.
Assume that n =6 for this problem.
for (int i =1; i < n ; i ++){
for (int k =0; k < i ; k ++){
System . out . print ("*") ;
}
System . out . println () ;f
}
6. Consider the following code and determine how many times "Grape" will be printed to the console. The solution should be stated in O() notation
for (int i =0; i < n ; i ++){
for (int k =0; k < n ; k ++){
for ( int m =0; m < i ; m ++){
System . out . println (" Grape ") ;
}
}
}
7. Consider the following code and determine how many times "Grape" will be printed to the console. The solution should be stated in O() notation
for (int i =0; i < n ; i ++){
for (int k =0; k < i ; k ++){
for ( int m =0; m < k ; m ++){
System . out . println (" Grape ") ;
}
}
}
8. Consider the following code and determine how many times "Grape" will be printed to the console. The solution should be stated in O() notation
for (int i =0; i < n ; i ++){
for (int k =0; k <100; k ++){
for ( int m =0; m < n ; m ++){
System . out . println (" Grape ") ;
}
}
}
9. Consider the following code and determine how many times "Grape" will be printed to the console. The solution should be stated in O() notation
int i = n ;
while ( i >=1){
for ( int k =0; k < n ; k ++){
System . out . println (" Grape ") ;
}
i =(int) i /3;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!