Question

What is the running time of the best possible big o function of n? 1. for(k...

What is the running time of the best possible big o function of n?

1.

for(k = 1; k <= 999*n; k+=n) z++;

2.

for(i = 1; i*i*i <= n; i++) z++;

3.

for(i = 1; i*i <= n; i++){

for(j = 1; j*j <= n; j++){

z++;

}

}

Example:

for(i = 1; i <= n; i++)z++;

running time is O(n);

Homework Answers

Answer #1
1.
for(k = 1; k <= 999*n; k+=n) z++;
Singe loop running for 1000n times.
So,
Time complexity = O(Largest term by removing constant) = O(n)

2.
for(i = 1; i*i*i <= n; i++) z++;
Singe loop running for cube root of n times.
So,
Time complexity = O(Largest term by removing constant) = O()

3.
for(i = 1; i*i <= n; i++){
    for(j = 1; j*j <= n; j++){
    z++;
    }
}
First loop running for sqrt(n) times.
Second loop running for sqrt(n) times.
Time complexity = O(Largest term by removing constant) = 
Know the answer?
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
Similar Questions
Analyze the following code and provide a "Big-O" estimate of its running time in terms of...
Analyze the following code and provide a "Big-O" estimate of its running time in terms of n. Explain your analysis. for ( int i = n; i > 0; i /= 2 ) { for ( int j = 1; j < n; j += 2 ) { for ( int k = 0; k < n; k += 2 ) { ... // constant number of operations } } }
find time complexity in terms of n? use big-O i,j,k,x =0; for i=0; i<=n; i++; for...
find time complexity in terms of n? use big-O i,j,k,x =0; for i=0; i<=n; i++; for j=0, j<=5; j++; for k=5; k<=n; k=k*5; x = x*n;
Analyze the following code and provide a "Big-O" estimate of its running time in terms of...
Analyze the following code and provide a "Big-O" estimate of its running time in terms of n. Explain your analysis. for (int i = n; i >= n; i = i/2)           some O(1) time statements; end for
1.) the following code fragments give running time analysis (Big Oh). Explain your answer: sum2 =...
1.) the following code fragments give running time analysis (Big Oh). Explain your answer: sum2 = 0; sum5 = 0; for(i=1; i<=n/2; i++) { sum2 = sum + 2; } for(j=1; j<=n*n; j++) { sum5 = sum + 5; } i think it is O(n^2) since big oh finds the order of worst case which is the the second loop being n^2 complexity. but im not sure. 2.) Give an efficient algorithm along with running time analysis to find the...
Show that the running time for the following segment of code is O(N3) without using the...
Show that the running time for the following segment of code is O(N3) without using the rule for loop. Make sure to count each statement that takes one unit of time. sum = 0; for( i = 0; i < n; i++ ) for( j = 0; j < n; j++ )             for( k = 0; k < n; k++ ) sum++;
What is the time complexity of the following code? (in big-O notaion) sum = 0 count...
What is the time complexity of the following code? (in big-O notaion) sum = 0 count = 0 var1 = 0 for: i=1 to n{ sum = sum+i for j=1 to [(3i+2i)(5n)(2i)]{ var1 = sum+count} } for m = i to j*j{ sum = sum*sum var2 = sum - (count+3)}
   1)T(n) = 27 T (n/3) + n3 2)Calculate the running time for the following code...
   1)T(n) = 27 T (n/3) + n3 2)Calculate the running time for the following code fragment. Algorithm test int counter, i, j; counter := 0; for (i:= 1; i < n; i*=2) { for (j:= 0; j < i; j++) { counter := counter +1 } } 3)Let f(n) = 2lg 8n + 3 be a function.
Analyze the worst case running time of the following code in “big-Oh” notation in terms of...
Analyze the worst case running time of the following code in “big-Oh” notation in terms of the variable n. a. void fdisp1(int n) { for(int i=0; i < n; i++) { for(int j=0; j < n; j++) { for(int k=0; k < n; k++) { for(int m=0; m < n; m++) { System.out.println("Hi I am Here"); } } } } } b. voidprintAllPossibleOrderedPairs(intarr[], int size) { for (int i = 0; i < size; i++) { for (int j =...
Let T(n) be the running time of function do_something. Find the equation of T(n) and find...
Let T(n) be the running time of function do_something. Find the equation of T(n) and find the complexity of T(n) using big-O notation. def do_something(L): s = 0 for x in L: s = s + x print(s) for y in L: s = s + y print(s,x,y) for z in L: s = s + z s = s * 5 return s
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...