Question

What is the complexity of the following nested loops? for i = n to 1 step...

What is the complexity of the following nested loops?

for i = n to 1 step -1 do

    j ← i

    while j ≥ 1

                                   Θ(j) statement

                                 j ←   ëj/2û

                            endwhile

                        endfor

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

alade ( j 21) -70(%) etd wlile entd for ora

Add a comment
Know the answer?
Add Answer to:
What is the complexity of the following nested loops? for i = n to 1 step...
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
  • Poly-Poly + a[i] * power 6. (15%) Consider the nested loops shown below, where N is...

    Poly-Poly + a[i] * power 6. (15%) Consider the nested loops shown below, where N is assumed to be a power of 2. i.e., N-2 for some positive integer k. i=N; while (i>-1){ while (j =N){ j-2 *j; i=i/2. a) Determine the number of outer iterations (associated with the outer while loop) to be executed? Show your work. b) For each outer iteration (for each value of i), determine the number of iterations of the inner while loop to be...

  • Computer Science I home> 4 8 Nested loops Feedback | 48.1 Nested loops Indent text Print...

    Computer Science I home> 4 8 Nested loops Feedback | 48.1 Nested loops Indent text Print numbers 0, 1,2userNum as shown, with each number indented by that number of spaces For each printed line, print the leading spaces, then the number, and then a newline Hint. Use i and j as loop variables (initialize i and j explicitly). Note. Avoid any other spaces like spaces after the printed number Ex userNum-3 prints

  • Convert the following nested for loop into a nested while loop: for(i = 1 ; i...

    Convert the following nested for loop into a nested while loop: for(i = 1 ; i <= rows; i++)                     {                         for (j = 1 ; j <= rows; j++)                             {                                 if (bombCells[i][j])                                     {                                         System.out.print(" * ");                                     }                                 else                                     {                                         System.out.print(" . ");                                     }                             }                         System.out.println();                     }

  • Plz use nested loops , read the question carefully, i need help step by step solution...

    Plz use nested loops , read the question carefully, i need help step by step solution using ( spyder).. Exercise 2 Write a Python program (Lab7-ex2.py) that reads from the user an integer n, displays the triangular number sequence up to the n term (ie. 1,3, 6, 10,. n"term). The triangular of a number n is calculated as "n(n+1)/2" where n is a nonzero positive number. Note that your program should display a suitable error message if n is entered...

  • 1- Find the time complexity of the following program, where n is given as input: i...

    1- Find the time complexity of the following program, where n is given as input: i = n; while (i > 1) { j = i; while (j < n) { k = 0; while (k < n) { k += 2; } j *= 2; } i /= 2; } Express your answer using theta notation, and explain the amount of time it takes for each loop to finish.

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • AT46.1: Nested loops: Indent text HALLENGE 461: Nested loops: Indent text Print numbers 0,1,2 userNum as...

    AT46.1: Nested loops: Indent text HALLENGE 461: Nested loops: Indent text Print numbers 0,1,2 userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex userNum-3 prints 3 int noin(void){ 6 int 1- Your solution goes here 1e return...

  • Write a recurrence relation describing the worst-case running time of each of the following algor...

    Write a recurrence relation describing the worst-case running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution by using substitution or a recursion tree. You may NOT use the Master Theorem. 上午1:46 3月21日周四 令52%. " 5. endfor 6. return (r); function func4(A, n) *Aarray of n integers */ 1. if n s 20 then return (A[n]); 4. while (i < n/2) do 7. endwhile 8. x...

  • What is the time-complexity of the algorithm abc? Procedure abc(n: integer) s := 0 i :=1...

    What is the time-complexity of the algorithm abc? Procedure abc(n: integer) s := 0 i :=1 while i ≤ n s := s+1 i := 2*i return s consider the following algorithm: Procedure foo(n: integer) m := 1 for i := 1 to n for j :=1 to i2m:=m*1 return m c.) Find a formula that describes the number of operations the algorithm foo takes for every input n? d.)Express the running time complexity of foo using big-O/big-

  • I need to now how to input the following code into the complier for C++ code....

    I need to now how to input the following code into the complier for C++ code. It is for chapter 8 question 7a in the PLD book // Start //     Declarations //         num MAXADS = 100 //         num adcatcode[MAXADS] //         num adwords[MAXADS] //         num curCode //         num numads //         num i //         num j //         num k //         num subtotal //         num temp //     output "Please enter the number of ads: " //     input numads //     if ((numads > 0)...

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