Question

For each of the following problems, simplify and express your answer as Θ(nk) or Θ(nk(log n wherever possible. If the asymptotic running time is exponential, then just give exponential lower bounds. Random(n) generates a random number between 1 and n with uniform distribution (every integer between 1 and n is equally likely.) CoinFlip) returns heads or tails with equal probability.Consider the following ution: Func5 (A, n) A is an array of inlegers 1 if (n <10 the retur (A]) 2 840; s for<1 to n do 6 end 7 for i← 1 to 3 do k← Random(n); (kS 2n/3) then s+Func5(A, n/3) 0 end 11 return (»); (a) What is the asympttc worst case running time of Func5 ustify your solution (b) What is the asymptotic expected running time of Func5 Justify your solution

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

Given,

Random generate a random number between 1 to n. So, it has to trigger a event to select a number between 1 to n with complexity on constant value.

The function is recursive in nature.

1. The first if condition is initial condition to trap value and end recursion and evaluate the value.

2. Second for block runs from 1 to n take O(n) time and increments the value of s as a sum.

3. Third for block runs const but the line no 9 feed the value into recursion chain with value n bringing near O(log n)

(a). The asymptotic worst case running time of Func5 will be O(n2).

(b). The asymptotic expected running time of Func5 will be O(n log n)

For better understanding we can take example value and go through program step wise and get the value and aggregate the value in terms of n, neglecting constant values.

Add a comment
Know the answer?
Add Answer to:
For each of the following problems, simplify and express your answer as Θ(nk) or Θ(nk(log n...
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
  • For each of the following problems write a recurrence relation describing the running time of eac...

    For each of the following problems write a recurrence relation describing the running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution using substitution and carefully computing lower and upper bounds for the sums. Simplify and express your answer as Θ(n k ) or Θ(n k (log n)) wherever possible. If the algorithm takes exponential time, then just give exponential lower bounds. 5. func5 (A,n) /*...

  • Write a recurrence relation describing the worst case running time of each of the following algorithms,...

    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. Simplify your answers, expressing them in a form such as O(nk) or (nklog n) whenever possible. If the algorithm takes exponential time, then just give an exponential lower bound using the 2 notation. function...

  • Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case...

    Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case time and insertion sort runs in Θ(n 2 ) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of...

  • 1. For each function defined below, find the value of k such that s(n) = O(nk)....

    1. For each function defined below, find the value of k such that s(n) = O(nk). For part (a), justify your answer from the definitions of O, O, and by finding explicit constants that work, following the examples in Proofs 7.2.1 and 7.2.3 in the zyBook. Don't just refer to Theorem 7.2.2. For part (b), you do not need to find explicit constants, just explain why your answer is correct. (a) s(n) = (2n + 1)(5n2+1) (b) s(n) = nºt(n)...

  • 1. What is the worst case time complexity of insertion into a binary search tree with...

    1. What is the worst case time complexity of insertion into a binary search tree with n elements? You should use the most accurate asymptotic notation for your answer. 2. A binary search tree is given in the following. Draw the resulting binary search tree (to the right of the given tree) after deleting the node with key value 8. 10 3. You have a sorted array B with n elements, where n is very large. Array C is obtained...

  • 3. Determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution...

    3. Determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution using expansion/substitution and upper and/or lower bounds, when necessary. You may not use the Master Theorem as justification of your answer. Simplify and express your answer as O(n*) or O(nk log2 n) whenever possible. If the algorithm is exponential just give exponential lower bounds c) T(n) T(n-4) cn, T(0) c' d) T(n) 3T(n/3) c, T() c' e) T(n) T(n-1)T(n-4)clog2n, T(0) c' 3. Determine the...

  • Suppose the following is a divide-and-conquer algorithm for some problem. "Make the input of size n...

    Suppose the following is a divide-and-conquer algorithm for some problem. "Make the input of size n into 3 subproblems of sizes n/2 , n/4 , n/8 , respectively with O(n) time; Recursively call on these subproblems; and then combine the results in O(n) time. The recursive call returns when the problems become of size 1 and the time in this case is constant." (a) Let T(n) denote the worst-case running time of this approach on the problem of size n....

  • Give the asymptotic bounds for T(n) in each of the following recurrences. Make your bounds as...

    Give the asymptotic bounds for T(n) in each of the following recurrences. Make your bounds as tight as possible and justify your answers. Assume the base cases T(0)=1 and/or T(1) = 1. 1. T(n) = T(n-1) + 2n 2. T(n) = T(n-2) = 3

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

  • Question 1. (1 marks) The following procedure has an input array A[1..n] with n > 2...

    Question 1. (1 marks) The following procedure has an input array A[1..n] with n > 2 arbitrary integers. In the pseudo-code, "return” means immediately erit the procedure and then halt. Note that the indices of array A starts at 1. NOTHING(A) 1 n = A. size 2 for i = 1 ton // i=1,2,..., n (including n) 3 for j = 1 ton // j = 1,2,...,n (including n) 4. if A[n - j +1] + j then return 5...

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