Question: The following is a python pseudo-code. I have a few questions about it below. 1. What is N[1] = 1 translate to in code? Originally

The following is a python pseudo-code. I have a few questions about it below.

The following is a python pseudo-code. I have a few questions about1. What is N[1] = 1 translate to in code? Originally I thought N[1] = 1 was some kind of special dynamic programming keyword or something of the sort. However, N[1] = 1 the compiler complains N is not defined. So what are N[1] = 1 and F[1] = 1? If they are lists, how would I go about initializing these arrays in relation to dynamic programming with this pseudo code?

2. for i = 2 to n do? What does that mean and how does that translate to python code?

3. I've already implemented an iterative and recursive solution for this pseudo code. However, I'm having difficultly understanding the dynamic programming portion of it. Any advice on adding a dynamic programming solution to my recursive solution (i.e., like add an extra list or something like that)?

Dynamic Programmming: Activity Selection DP-ACTIVITY-SELECTOR (s, f) 1. n - length[s] 2. N[1: 1 /umber of activities in S1 3. F[1]-1 // last activity in S1 4. for 2 to n do 5. let k be the last activity finished before s, 6. if (N[i-1] > N[k]) then Case 1 7. 8 9. else// Case 2 10. Nli]- N[i-1] Fli]- F[i-1] How to output Sn? Backtrack! Time Complexity? O(n lg n) Dynamic Programmming: Activity Selection DP-ACTIVITY-SELECTOR (s, f) 1. n - length[s] 2. N[1: 1 /umber of activities in S1 3. F[1]-1 // last activity in S1 4. for 2 to n do 5. let k be the last activity finished before s, 6. if (N[i-1] > N[k]) then Case 1 7. 8 9. else// Case 2 10. Nli]- N[i-1] Fli]- F[i-1] How to output Sn? Backtrack! Time Complexity? O(n lg n)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!