Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

Students also viewed these Databases questions

Question

=+ a. How does this change affect the incentives for working?

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago