Question

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) /* A = array of n integers 1 if (n 1) then return Al 3 x = A [n/2] + A[n] 5 x =x+ func5 (A, 2n/3) 2 4 6 return

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

We clear explained each line with the complexity, for constant line complexity will be o(1) or constant both same.

If we call any function then complexity will be depends upon the function call , if n is divided in n/2 parts then TC will be

T(n/2) if divided in 4 parts the it will be T(n/4) so on ...

In this problem n is divided in 2n/3 parts so TC will be T(n/3) .

k- hms ㄦケ叹!chon leie aj ler So\.my the ,< c u γχ ne 3

Add a comment
Know the answer?
Add Answer to:
For each of the following problems write a recurrence relation describing the running time of eac...
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
  • 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...

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

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

  • For each of the following problems, simplify and express your answer as Θ(nk) or Θ(nk(log n...

    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])...

  • The task was to find the recurrence relation for this function and then find the complexity...

    The task was to find the recurrence relation for this function and then find the complexity class for it as well. Provided is my work and the function. My question is, I feel like I'm missing some step in the recurrence relation and complexity class. Is this correct? The following code is in JavaScript. function divideAndConquerSum(x){ if(x.length<1){ return 0; } if(x.length == 1){ return x[0]; } var third = Math.floor((x.length-1)/3); var next = (third *2)+1; var y = x.slice(0, third+1);...

  • 1. Algorithm write recurrence relation Help? Consider a version of merge sort in which an array...

    1. Algorithm write recurrence relation Help? Consider a version of merge sort in which an array of size n is divided into 5 segments of sizes n/5. Write the recurrence relation for the time complexity and solve it. (Show all your work.)

  • 2. Give the asymptotic running time of each the following functions in e notation. That is,...

    2. Give the asymptotic running time of each the following functions in e notation. That is, write down a recurrence relation for each recursive function below and solve it. Show your work def Pow(x, n): 2 if n-0: 3 return 1 end 5 e f Pow(x, [n/2]) 1 # n is even if n % 2-0: 9 return f f 10 end #nis odd 12return r*f*.f 13 end

  • Consider the following: Algorithm 1 Smallest (A,q,r) Precondition: A[ q, ... , r] is an array...

    Consider the following: Algorithm 1 Smallest (A,q,r) Precondition: A[ q, ... , r] is an array of integers q ≤ r and q,r ∈ N. Postcondition: Returns the smallest element of A[q, ... , r]. 1: function Smallest (A , q , r) 2: if q = r then 3: return A[q] 4: else 5: mid <--- [q+r/2] 6: return min (Smallest(A, q, mid), Smallest (A, mid + 1, r)) 7: end if 8: end function (a) Write a recurrence...

  • For each of the following recursive methods available on the class handout, derive a worst-case recurrence...

    For each of the following recursive methods available on the class handout, derive a worst-case recurrence relation along with initial condition(s) and solve the relation to analyze the time complexity of the method. The time complexity must be given in a big-O notation. 1. digitSum(int n) - summing the digits of integer: int digitSum(int n) {                 if (n < 10)                                 return n;                 return (digitSum(n/10) + n%10); } 2. void reverseA(int l, int r) - reversing array: void...

  • How many of the below given sequences is a solution to the following recurrence relation: an...

    How many of the below given sequences is a solution to the following recurrence relation: an = an-1 + 2an-2 +2n - 9? 1.) an = 2n + n - 2 2.) an = 72n - n + 2 3.) an = 5(-1)n - n + 2 4.) an = 2 - n 5.) an = 2(-4)n + 3

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