Question

A function f(i,j) satisfies the following recurrence relation and boundary conditions. f(i,j) = { 0 if...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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.

Add a comment
Know the answer?
Add Answer to:
A function f(i,j) satisfies the following recurrence relation and boundary conditions. f(i,j) = { 0 if...
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
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