A function f(i,j) satisfies the following recurrence relation and boundary conditions.
f(i,j) = { 0 if i=0 or j=n+1
{ 1 + max{f(i, j+1), f(i-1,j)} otherwise
Write a non-recursive algorithm to compute the value of f(i,j) for all 1<=i<=n, 1<=j<=n
int max(int a, int b) {
if(a > b) {
return a;
}
return b;
}
int f(int r, int c) {
int values[n+1][n+1];
for(int i=0; i<=n; i++) {
values[0][i] = 0;
values[i][n] = 0;
}
for(int i=1; i<=n; i++) {
for(int j=n-1; j>=0; j--) {
values[i][j] = 1 + max(values[i][j+1], values[i-1][j]);
}
}
return f[r-1][c-1];
}
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
A function f(i,j) satisfies the following recurrence relation and boundary conditions. f(i,j) = { 0 if...
Question 1. A linear homogeneous recurrence relation of degree 2 with constant coefficients is a recurrence relation of the form an = Cian-1 + c2an-2, for real constants Ci and C2, and all n 2. Show that if an = r" for some constant r, then r must satisfy the characteristic equation, p2 - cir= c = 0. Question 2. Given a linear homogeneous recurrence relation of degree 2 with constant coefficients, the solutions of its characteristic equation are called...
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...
3. [4] The solution of the wave equation02, which satisfies the boundary conditions u(0,t) = u(2,t) 0, is given by a cos+b sin If u(, t) satisfies the initial conditions u(x, 0)-0 and u(x,0)3sin(Tx) - sin(3T), find the coefficients an and bn Solution: b2 = , bs =- π 97T bn-0 otherwise, and an - 0 for all n 21.
3. [4] The solution of the wave equation02, which satisfies the boundary conditions u(0,t) = u(2,t) 0, is given by...
Suppose f:N → N satisfies the recurrence f(n+1) = f(n) 7. Note that this is not enough information to define the function, since we don't have an initial condition. For each of the initial conditions below, find the value of f(7). a. f(0) = 1. $(7) = b. f(0) = 5. f(7) = c. f(0) = 19. f(7) = d. f(0) = 249. f(7) =
Problem 3 (10 points) Suppose a sequence satisfies the below given recurrence relation and initial conditions. Find an explicit formula for the sequence a -6a--9a,-2 for all integers k2 2 ao = 1, a1 = 3
3. 0 marks Suppose you have an algorithm which has the following recurrence relation for W(n), assuming n is a power of 2, i.e. assuming n-2, k20: for n for n- W()-2W(n/2)+2n+ 2 W(n)- Using back substitution and assuming n is a power of 2, ie. n-2, find an exact (ie non-recursive) formula for Win). Be sure to show your work and to simplify your final answer as much as possible. Note that you do NOT need to verify your...
For the following recursive function: Derive a recurrence relation, solve the relation, prove the solution is correct, and find its big-O notation. String f2(String s, char c) { if (s.length() == 0) return s; if (s.charAt(0) == c) return f2(s.substring(1), c); else return s.charAt(0) + f2(s.substring(1), c); }
The function u(x, t) satisfies the partial differential equation with the boundary conditions u(0,t) = 0 , u(1,t) = 0 and the initial condition u(x,0) = f(x) = 2x if 0<x<} 2(1 – x) if}<x< 1 . The initial velocity is zero. Answer the following questions. (1) Obtain two ODES (Ordinary Differential Equations) by the method of separation of variables and separating variable -k? (2) Find u(x, t) as an infinite series satisfying the boundary condition and the initial condition.
5. Let F(n, m) denote the number of paths from top-left cell to bottom-right cell in a (n x m) grid (that only permits moving right or moving down). It satisfies the recurrence relation F(n, m) F(n-1, m) + F(n, m-1) What should be the initial condition for this recurrence relation? (Hint: What would be the number of paths if there was only a single row or a single column in the grid?)[5] Convince yourself that F(n, m) gives correct...
8. Consider the following simultaneous homogeneous recurrence relations: 3a-12bn-1 bn-an-1 + 2bn-1 for n > 1, with initial conditions ao 1 and bo - 0 (a) Find the generating function for an and then solve for an b) What is the homogeneous recurrence relation that an satisfies? (c) Repeat (a) and (b) for bn 72.
8. Consider the following simultaneous homogeneous recurrence relations: 3a-12bn-1 bn-an-1 + 2bn-1 for n > 1, with initial conditions ao 1 and bo - 0...