Question

(b) Consider the following algorithm for (i = n; i >-1; i i/2) for j in range [1, i] Constant Number of Operations Derive the run time of the above algorithm (as a function of n). You must formally derive the run-times (merely stating run times or high level explanation of run time do not suffice)

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

Hi, Please find my answer.

Please let me know in case of any issue.

2. n. 0 2 aceeding to explanation 2- 千 ner-

Add a comment
Know the answer?
Add Answer to:
(b) Consider the following algorithm for (i = n; i >-1; i i/2) for j in...
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
  • consider this segment of an algorithm: for i := 1 ton n for j:=1 to n...

    consider this segment of an algorithm: for i := 1 ton n for j:=1 to n top:=ij+j+10 a. find a function f(n) that counts the number of multiplication and additions performed in this segment. b. Give a big O estimate for the number of additions and multiplications used in the segment

  • Algorithm Analysis: Study the following sorting algorithm.    SORT( A[1...n]) bound <- Length(A) -1 for i...

    Algorithm Analysis: Study the following sorting algorithm.    SORT( A[1...n]) bound <- Length(A) -1 for i <- 1 to Length(A) newbound <- 0 for j <- 0 to bound    if A[j] > A[j + 1]    swap( A[j], A[j + 1] ) newbound = j -1 bound <- newbound (a) Use the longer approach described in lecture 3 week 1 that we used in analyzing Insertion-Sort to compute the running time T(n) of the above SORT algorithm. You may...

  • Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer...

    Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer numbers for i leftarrow† 0 to n - 2 do for j leftarrow†† i +1 to n - 1 do if A[i] = = A[j] return false return true a) What does this algorithm do? b) Compute the running time of this algorithm.

  • Analyze the running time of the following algorithms asymptotically. (a) Algorithm for-loop(n): P = 1 for...

    Analyze the running time of the following algorithms asymptotically. (a) Algorithm for-loop(n): P = 1 for i = 1 to 5n^2 do p = p times i return p (b) Algorithm for-loop(n): s = 0 for i = 1 to n do for j = I to n do s = s + i return s (c) Algorithm WhileLoop(n): x = 0; j = 2; while (j = n){x = x+ 1; j =j times 2;}

  • 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++)...

  • 1. Suppose that d ≥ 2 is an integer constant. In a d-ary tree, each node...

    1. Suppose that d ≥ 2 is an integer constant. In a d-ary tree, each node has at most d nonempty subtrees. For example, the trees discussed along with heaps had d = 2. We can represent a nearly complete d-ary tree with n nodes using an array whose indexes range from 0 to n−1. (This is different from Cormen’s arrays, whose indexes range from 1 to n.)       Suppose that i is the index of a node in the...

  • Question No.1 [CLO 1][7 marks] 1. Consider the following pseudocode: Algorithm IterativeFunction (a, b) // a...

    Question No.1 [CLO 1][7 marks] 1. Consider the following pseudocode: Algorithm IterativeFunction (a, b) // a and b are integers while (a>0) B- a/2 A a-2 end while return b; i. What is the time complexity of the IterativeFunction pseudocode shown above? ii. What is the space complexity of the IterativeFunction pseudocode shown above? 2. What is the time complexity of the following algorithm (Note that n(n+1) 2,2 n(n+1)(2n+1) 2 and ): Provide both T(n) and order, e(f(n)). int A=0;...

  • fundamental algorithm AllLessThan1 (int C A, B) return bool for (i-1 to |AI) for (j-1 to B if (A[1] >=B[j]) ret...

    fundamental algorithm AllLessThan1 (int C A, B) return bool for (i-1 to |AI) for (j-1 to B if (A[1] >=B[j]) return FALSE ; return TRUE; AllLessThan2 (int[] A,B) return bool largeAA[1] for (i 2 to |AI) if (A[i] > largeA) largeA A[i]; for (j = 1 to IBD if (largeA >= B[j]) return FALSE; return TRUE; C. For any particular arrays A, B, let ti(A, B) and t2(A, B) be the running times of the two algo- rithms for inputs...

  • (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...

  • Given the following code, find their big(O) for I in range of n:          for j...

    Given the following code, find their big(O) for I in range of n:          for j in range of n:                  for k in range of 10000:                                 print(“test”) If an algorithm takes n3+1000n2+1000n2+9999 time, what is the Big O for this algorithm? Proof: O(nK) < O (2n), need to do some research on polynomial time and exponential time.

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