Question

Determine the output of each algorithm below the number of assignment operations in each (show work)...

Determine

  1. the output of each algorithm below
  2. the number of assignment operations in each (show work)
  3. the number of print operations in each (show work)
  4. the complexity of each algorithm in terms of Big O notation (show work)

2.

Let n be a given positive integer, and let myList be a three-dimensional array with capacity n for each dimension.

for each index i from 1 to n do

{

for each index j from 1 to n/2 do

{

for each index k from 1 to n/2 do

{

                myList[ i ] [ j ] [ k ] = i;

Print the element at myList[ i ] [ j ] [ k ];
}

}

}

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

Output determination:-

1 will get printed (n/2)*(n/2)

2 will get printed (n/2)*(n/2)

3 will get printed (n/2)*(n/2)

.

.

.

n will get printed (n/2)*(n/2)

So we can say each iteration or vakue of i get executed (n/2)*(n/2) times

As we n/2 is approximately equal to logn

So the time complexity is here

O(nlognlogn)

Add a comment
Know the answer?
Add Answer to:
Determine the output of each algorithm below the number of assignment operations in each (show work)...
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
  • Show your work Count the number of operations and the big-O time complexity in the worst-case...

    Show your work Count the number of operations and the big-O time complexity in the worst-case and best-case for the following code int small for ( i n t i = 0 ; i < n ; i ++) { i f ( a [ i ] < a [ 0 ] ) { small = a [ i ] ; } } Show Work Calculate the Big-O time complexity for the following code and explain your answer by showing...

  • URGENT Question 3 25 pts ArrayMystery: Input: n: a positive integer Pseudocode: Let output be an...

    URGENT Question 3 25 pts ArrayMystery: Input: n: a positive integer Pseudocode: Let output be an empty array For i = 1 to n j = 1 While ij <= n Addj to the end of output j - j + 1 Return output Answer the following questions about the ArrayMystery algorithm above. a) How many times will the inner while loop iterate? You should express your answer in terms of i and n, using Big-Oh notation. Briefly justify your...

  • Problem 1: Let W(n) be the number of times "whatsup" is printed by Algorithm WHATSUP (see below) ...

    Problem 1: Let W(n) be the number of times "whatsup" is printed by Algorithm WHATSUP (see below) on input n. Determine the asymptotic value of W(n). Algorithm WHATSUP (n: integer) fori1 to 2n do for j 1 to (i+1)2 do print("whatsup") Your solution must consist of the following steps: (a) First express W(n) using summation notation Σ (b) Next, give a closed-form formula for W(n). (A "closed-form formula" should be a simple arithmetio expression without any summation symbols.) (c) Finally,...

  • 1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark...

    1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark 1729 is O(1) b) 3 marks 2n2-4n -3 is O(n2) 2. [3 marks] Using the definition of Big-Oh, prove that 2n2(n 1) is not O(n2) 3. 6 marks Let f(n),g(n), h(n) be complexity functions. Using the definition of Big-Oh, prove the following two claims a) 3 marks Let k be a positive real constant and f(n) is O(g(n)), then k f(n) is O(g(n)) b)...

  • Need to find number of elementary expressions in terms of n, not looking for Big O...

    Need to find number of elementary expressions in terms of n, not looking for Big O complexity. 4. Work out the number of elementary operations in the worst possible case and the best possible case for the following algorithm (justify your answer): 0: function Nonsense (positive integer n) 1: it1 2: k + 2 while i<n do for j+ 1 to n do if j%5 = 0 then menin else while k <n do constant number C of elementary operations...

  • Exercise 1 Use Top-Down Design to “design” a set of instructions to write an algorithm for...

    Exercise 1 Use Top-Down Design to “design” a set of instructions to write an algorithm for “travel arrangement”. For example, at a high level of abstraction, the algorithm for “travel arrangement” is: book a hotel buy a plane ticket rent a car Using the principle of stepwise refinement, write more detailed pseudocode for each of these three steps at a lower level of abstraction. Exercise 2 Asymptotic Complexity (3 pts) Determine the Big-O notation for the following growth functions: 1....

  • JAVA What is the complexity of this algorithm? Assign each student in the class a number...

    JAVA What is the complexity of this algorithm? Assign each student in the class a number from 1 to n, where n is the number of students. Then ask each of the odd-numbered students whether he or she is left-handed. a. O(1) b. O(n) c. O(n ^ 2) d. O(log n) What is the complexity of this algorithm? In a very difficult CS class, half the n students who originally signed up drop the course after the first quiz. After...

  • Consider the following pseudocode: Algorithm RecursiveFunction (a, b) // a and b are integers if (as1...

    Consider the following pseudocode: Algorithm RecursiveFunction (a, b) // a and b are integers if (as1 ) return b; else return RecursiveFunction (a-2, a/2); endif a. What is the time complexity of the RecursiveFunction pseudocode shown above? b What is the space complexity of the RecursiveFunction pseudocode shown above? n(n+1) C. What is the time complexity of the following algorithm (Note that 21-, i = n(n+1)(2n+1). and Σ.,1 ): Provide both T(n) and order, Ofn)). int A=0; for (int i=0;i<n;i++)...

  • 2. Measure the complexity of the following algorithm: SHOW your work. (15 points) a=1 b 3:...

    2. Measure the complexity of the following algorithm: SHOW your work. (15 points) a=1 b 3: for (i = 0, i<= n, i++) d-d-1 for (j:0, j <= n, j++) c=a+b;

  • (V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a...

    (V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a list of n integers) for i = 2 to n do c= j=i-1 while (j > 0) do if ra; then break end if 4j+1 = a; j= j-1 end while j+1 = 1 end for 14: return 0.02. 1, 15: end procedure Answer the following questions: (1) Run the algorithm with input (41, 02, 03, 04) = (3, 0, 1,6). Record the values...

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