

(5 x 2 = 10 pts) Consider the following functions. For each of them, determine how...
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, 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 recurrence T (n) = T (⌈n/4⌉) + T (⌈n/3⌉) + n with T (1) = 1. 12 points (a) (4 Points) Using a recursion tree, determine a tight asymptotic upper bound on T(n). (b) (4 Points) Prove your upper bound using induction. (c) (4 Points) Using a suitable variable change, solve the recurrence U (n) = 3U (⌈n^(1/3) ⌉) + 7 with U(2) = 1.
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, 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] 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):...
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 + "...
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), 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...
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....