Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A dynamic programming algorithm for solving the Activity Selection problem from

ID: 662862 • Letter: A

Question

A dynamic programming algorithm for solving the Activity Selection problem from chapter 16 fills an n by n table c so that c[1,n] contains the maximal number of schedulable activities. Only the entries for which i <= j are filled. Assuming the table is oriented with row 1 at the top, for the algorithm to compute a value for entry c[i,j], it must access the i-1 entries to the left of and the j-1 entries below c[i,j].

a. In terms of i, j, and n, how many times is entry c[i,j] accessed? (Hint: Try determining the answer for a 4-by-4 table and then generalize.)

b. In terms of n what is the ?-notation for the total number of accesses over all entries?

Explanation / Answer

While solving algo with Dynamic Programming is a technique which is based on some recurrent formula. And a sub-solution of the problem is constructed from previously found ones.

Algo for Part a :-

============================

int i, j, k;

for (i = 0; i < n; ++i)
{
for (j = 0; j < n; ++j)
{
C[i][j] = 0;

for (k = 0; k < n; ++k)
C[i][j] += A[i][k] * B[k][j];

}

}

Part b. The total number of accesses over all the entries -

============================

for (ii = 0; ii < N; ii += ib)
{

for (kk = 0; kk < N; kk += kb)
for (j=0; j < N; j += 2)
for (i = ii; i < ii + ib; i += 2 )

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote