Question

2. Give the asymptotic running time of each the following functions in e notation. That is, write down a recurrence relationdef 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Recursive relation
T(n) = T(n/2) + c
Where c is a constant.

T(n) = T(n/2) + c
     = T(n/4) + c + c
     = T(n/8) + c + c + c
     ......
     ......
     ......
     = T(n/n) + c + .... + c + c + c [log(n) +1 terms]
     = c + c + .... + c + c + c [log(n) +1 terms]
     = clog(n)
     = Theta(logn)

Note: Please comment below if you have any doubts

Please up vote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
2. Give the asymptotic running time of each the following functions in e notation. That is,...
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...

  • 6. Using big-oh notation, give the runtime for each of the following recursive functions. You do...

    6. Using big-oh notation, give the runtime for each of the following recursive functions. You do not need to justify your answers: a) Int nonesense (int n) if (n <0) return 1; return nonsense (n-2) 1; b) int no nonesense (int n) if (n <0) return 1; return no_nonsense (n-1)+ no nonsense (n-1)

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

  • PROBLEM 1 (24 points): For each of the recursive functions below and on the next page,...

    PROBLEM 1 (24 points): For each of the recursive functions below and on the next page, give a correct recurrence relation expressing its runtime and then a tight runtime bound for the recurrence relation. Functions that take parameters lo and hi: n=hi-lo+1 RECURRENCE RELATION: int foo(int a[], int lo, int hi) { int x, i, j, m; X = 0; if(lo==hi) return a[10]; for(i=lo; i<=hi; i++) { for(j=i+1; j<=hi; j++) { if(a[i] % 2) x += a[i]; else x -=...

  • (5 x 2 = 10 pts) Consider the following functions. For each of them, determine how...

    (5 x 2 = 10 pts) Consider the following functions. For each of them, determine how many times is ‘hi' printed in terms of the input n (i.e in Asymptotic Notation of n). You should first write down a recurrence and then solve it using the recursion tree method. That means you should write down the first few levels of the recursion tree, specify the pattern, and then solve. (a) 1 2 3 def fun(n) { if (n > 1)...

  • Compute the total running time for each of the functions in the following code. First, compute...

    Compute the total running time for each of the functions in the following code. First, compute the running time in terms of some constants a, b, c, d, e, etc. Show your work and give the answer in the text box. Then give the tightest big-O bound you can for each. (All of the functions are O(n!), but you can give a more informative bound for each.) void f(int n) {   int i = 1;   while (i <= sqrt(n)) {...

  • Example 3: The Growth of Functionsand Asymptotic notation a) Show that x is O(x )but that...

    Example 3: The Growth of Functionsand Asymptotic notation a) Show that x is O(x )but that r is not O(x b) Give as good a big-O estimate as possible for each of the following (A formal proof is not required, but give your reasoning): log,n! 7n n +nlo 3n2 +2n+4 . (n log, (log,n") 2 42" c) Which of the functions in part b) above has the fastest growth rate? d) Show that if f(x) is Ollog, x)where b>1, and...

  • The following algorithm (Rosen pg. 363) is a recursive version of linear search, which has access...

    The following algorithm (Rosen pg. 363) is a recursive version of linear search, which has access to a global list of distinct integers a_1, a_2,..., a_n. procedure search(i, j, x : i,j, x integers, 1 < i < j < n) if a_i = x then return i else if i = j then 4. return 0 else return search(i + 1, j, x) Prove that this algorithm correctly solves the searching problem when called with parameters i = 1...

  • Consider the following Python function: def find_max (L): max = 0 for x in L: if...

    Consider the following Python function: def find_max (L): max = 0 for x in L: if x > max: max = x return max Suppose list L has n elements. In asymptotic notation, determine the best case running time as function of n In asymptotic notation, determine the worst case running time as function of n Now, assume L is sorted. Give an algorithm that takes asymptotically less time than the above algorithm, but performs the same function. Prove that...

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