Question

In: Computer Science

Let function F(n, m) outputs n if m = 0 and F(n, m − 1) +...

Let function F(n, m) outputs n if m = 0 and F(n, m − 1) + 1 otherwise.

1. Evaluate F(10, 6).

2. Write a recursion of the running time and solve it

. 3. What does F(n, m) compute? Express it in terms of n and m.

Solutions

Expert Solution

1)

F(n,m) = 1+F(n,m-1)

F(10,6) = 1+F(10,5)

= 1+(1+F(10,4))

= 2+F(10,4)

= 2+(1+F(10,3))

= 3+F(10,3)

= 3+(1+F(10,2))

= 4+F(10,2)

= 4+(1+F(10,1))

= 5+F(10,1)

= 5+(1+F(10,0))

= 6+F(10,0)

= 6+10 (F(n,0) returns n)

= 16

2)

The above function can be represented as follows:

F(n,m){

if(m=0)

return n;

else

return 1+F(n,m-1);

}

Therefore the recurrence relation would be

T(n,m) = T(n,m-1) + 1

= (T(n,m-2) + 1) + 1

= T(n,m-2) + 2

= (T(n,m-3) + 1) +2

= T(n,m-3) + 3

=T(n,m-k) +k (in general form)

we know that T(n,0)=1 because the function takes only one unit of time to return n value.

let m-k = 0 => m=k

substitute m=k in the above recurrence relation.

T(n,m) = T(n,0) + m

= 1 + m

Therefore the running time of the function F(n,m) is m+1

3)

F(n,m) computes the addition of n and m values.

F(n,m) = F(n,m-1) + 1

= (F(n,m-2) + 1) + 1

= F(n,m-2) + 2

= (F(n,m-3) + 1) +2

= F(n,m-3) + 3

= F(n,m-4) +4 and so on we continue up to F(n,m-m) + m

=> F(n,m) = F(n,0) + m = n+m


Related Solutions

Let f(x, y) be a function such that f(0, 0) = 1, f(0, 1) = 2,...
Let f(x, y) be a function such that f(0, 0) = 1, f(0, 1) = 2, f(1, 0) = 3, f(1, 1) = 5, f(2, 0) = 5, f(2, 1) = 10. Determine the Lagrange interpolation F(x, y) that interpolates the above data. Use Lagrangian bi-variate interpolation to solve this and also show the working steps.
Let f : Z × Z → Z be defined by f(n, m) = n −...
Let f : Z × Z → Z be defined by f(n, m) = n − m a. Is this function one to one? Prove your result. b. Is this function onto Z? Prove your result
Let f: [0 1] → R be a function of the class c ^ 2 that...
Let f: [0 1] → R be a function of the class c ^ 2 that satisfies the differential equation f '' (x) = e^xf(x) for all x in (0,1). Show that if x0 is in (0,1) then f can not have a positive local maximum at x0 and can not have a negative local minimum at x0. If f (0) = f (1) = 0, prove that f = 0
Let f:(a, b) → R be a function and n∈N. Assume that f is n-times differentiable...
Let f:(a, b) → R be a function and n∈N. Assume that f is n-times differentiable and f^(n)(x) = 0 for all x∈(a,b). Show that f is a polynomial of degree at most n−1.
Fibonacci Sequence: F(0) = 1, F(1) = 2, F(n) = F(n − 1) + F(n −...
Fibonacci Sequence: F(0) = 1, F(1) = 2, F(n) = F(n − 1) + F(n − 2) for n ≥ 2 (a) Use strong induction to show that F(n) ≤ 2^n for all n ≥ 0. (b) The answer for (a) shows that F(n) is O(2^n). If we could also show that F(n) is Ω(2^n), that would mean that F(n) is Θ(2^n), and our order of growth would be F(n). This doesn’t turn out to be the case because F(n)...
Let f(x) = {(C/x^n if 1≤ x <∞; 0 elsewhere)} where n is an integer >1....
Let f(x) = {(C/x^n if 1≤ x <∞; 0 elsewhere)} where n is an integer >1. a. Find the value of the constant C (in terms of n) that makes this a probability density function. b. For what values of n does the expected value E(X) exist? Why? c. For what values of n does the variance var(X) exist? Why?
Let f be a differentiable function on the interval [0, 2π] with derivative f' . Show...
Let f be a differentiable function on the interval [0, 2π] with derivative f' . Show that there exists a point c ∈ (0, 2π) such that cos(c)f(c) + sin(c)f'(c) = 2 sin(c).
1. Let g(s) = √ s. Find a simple function f so that f(g(s)) = 0....
1. Let g(s) = √ s. Find a simple function f so that f(g(s)) = 0. Hint: see Methods of computing square roots on Wikipedia. Use Newton’s method to estimate √ 2. Start with 3 different (and interesting) initial values of your choice and report the number of iterations it takes to obtain an accuracy of at least 4 digits. In python.
For f: N x N -> N defined by f(m,n) = 2m-1(2n-1) a) Prove: f is...
For f: N x N -> N defined by f(m,n) = 2m-1(2n-1) a) Prove: f is 1-to-1 b) Prove: f is onto c) Prove {1, 2} x N is countable
Let sn be a Cauchy sequence such that ∀n > 1, n ∈ N, ∃m >...
Let sn be a Cauchy sequence such that ∀n > 1, n ∈ N, ∃m > 1, m ∈ N such that |sn − m| = 1/3 (this says that every term of the sequence is an integer plus or minus 1/3 ). Show that the sequence sn is eventually constant, i.e. after a point all terms of the sequence are the same
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT