Question

IOs, mltipncation, division) counts as one step of the algorithm. sheet, the ith problem is worth pi points. The problems mus

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

For solving this dynamic programming question, we will have the vectors (or lists) P and F. Let us assume that the size of each is N.

At every index (i) the dynamic programming decision is Ans(P, F, i) = max(P(i) + Ans(P, F, i + 1+ F(i)), Ans(P, F, i+1))

Understanding the recursion:

We are deciding to find the max of two terms - Term 1: P(i) + Ans(P, F, i + 1 + F(i)) and Term 2: Ans(P, F, i+1)

Term 1 denotes the decision when we take up the given question and skip the next F(i) problems.

Term 2 denotes the decision when we don't take up the question (i) and think what if this question never exists at all.

Ans(P, F, i) is dependent on Ans(P, F, i + 1+ F(i)) and Ans(P, F, i+1)

This means that we have to solve from the last element since prior element solution depends on elements that appear latter.

Assume P = [1, 5, 1] F=[1,0,1]

We compute vec V of size 3 as follows

V[2] = Take P[2] since we don't have anything else so V[2] = 1

V[1] = Take either P[1] = 5 and add V[1 +1+ F[1]] = V[1+1+0] = V[2] = 1 so V[1] = 6. The other option was to not take P[1] and just take V[2] = 1. 6 > 1 we put V[1] = 6

V[0] = Take either P[0] and skip the next question F[0] = 1. so either V[0] = P[0] + V[2] or V[0] = V[1]. The simple answer is V[0] = V[1] = 6

Hence this is O(N) algorithm

Add a comment
Know the answer?
Add Answer to:
IOs, mltipncation, division) counts as one step of the algorithm. sheet, the ith problem is worth...
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
  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

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