Question

(5 x 2 = 10 pts) Consider the following functions. For each of them, determine how many times is ‘hi printed in terms of the1 2 def fun (n) { if (n > 1) { for i=1 to n { print( hihi ) 3 4 5 ها 6 fun(n/3) fun (n/3) 7 00 } 9}

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

a> T(n) = 27 (113) + constant 1 T(n) ty) Tin/3) +(1937) (1932) TM/3 -T(%3k) 11 Time complexity = 2 KAT -1 - 35 k= logan na =Tn)= n 2T | 3) + cost n n 20/3 2² n/3- /3 2/37 /3.5 /32 /k ak n/zk K=1093n #levels - Total #callo = kn+ 2 TC Max) logan n

Add a comment
Know the answer?
Add Answer to:
(5 x 2 = 10 pts) Consider the following functions. For each of them, determine how...
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
  • 2. Consider the following functions. For each of them, determine how many times is ‘hey’ printed...

    2. Consider the following functions. For each of them, determine how many times is ‘hey’ printed in terms of the input 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) def fun(n) { if (n > 1) { print( ‘hi’ ‘hi’ ‘hi’ ) fun(n/4) fun(n/4) fun(n/4) }} (b) def fun(n) {...

  • 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

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

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

  • Consider the following Python program: def fun(x, y): return x + y # [2] # [1]...

    Consider the following Python program: def fun(x, y): return x + y # [2] # [1] a = fun(2, 3) b = fun("2", 3) print a, b What does it evaluate to? Replace the last statement print a, b with print a + b and explain the traceback. What's wrong? Now eliminate the line marked [1] and change line [2] to read return x + y. Run the program and explain the traceback. Consider the following definition: def fun(n, m):...

  • Recussive

    Consider the following pseudocode: f(int n, int d) { println(space(d) + "n=" + n + " begins"); if (n > 1) { f(n/2, d+1); println(space(d+1) + "hi"); f(n/2, d+1); } println(space(d) + "n=" + n + " ends"); } where println(s) prints the string s on its own line, space(d) is a string of d spaces, and the + in the println means string concatenation. For example, if n=4 and d=2, the commands println(space(d) + "n=" + n + "...

  • 5. What is the Output? (2 x 5p each -10p) For cach of the following code snippets write down what...

    for java 5. What is the Output? (2 x 5p each -10p) For cach of the following code snippets write down what will be printed on the screen. (a) for(int a-0; a<5; a++) for (int b-0 b

  • Subject: Algorithm solve only part 4 and 5 please. need urgent. 1 Part I Mathematical Tools and Definitions- 20 points, 4 points each 1. Compare f(n) 4n log n + n and g(n)-n-n. Is f E Ω(g),fe 0(g)...

    Subject: Algorithm solve only part 4 and 5 please. need urgent. 1 Part I Mathematical Tools and Definitions- 20 points, 4 points each 1. Compare f(n) 4n log n + n and g(n)-n-n. Is f E Ω(g),fe 0(g), or f E (9)? Prove your answer. 2. Draw the first 3 levels of a recursion tree for the recurrence T(n) 4T(+ n. How many levels does it have? Find a summation for the running time. (Extra Credit: Solve it) 3. Use...

  • 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Yo...

    please explain each line of code! ( in python ) 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Your function should take one parameter, root node. You may assume that the tree only contains integers. You may not call any methods from the LinkedBinaryTree class. Specifically, you should traverse the tree in your function def binary tree even sum (root): Returns the sum of al1 even integers in the binary tree 2....

  • 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) /*...

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