Answer:
Explanation:
The maximum weighted independent collection of vertices in a linear chain graph is a straightforward algorithm whereby dynamic programming comes in handy.
Provided a linear chain graph G = (V, E, W), where V is a collection of vertices, E is a set of edges margins, and W is a weight feature function applied to each verex. Our goal is to find an independent collection of vertices in a linear chain graph with the highest total weight of vertices in that set.
We'll use dynamic programming to do this, with L[k] being the full weighted independent collection of vertices spanning from vertex 1 \to vertex k.
If we add vertex k+1 at vertex k+1, we cannot include vertex k, and thus L[k+1] would either be equivalent to L[k] when vertex k+1 is not being used, or L[k+1] = L[k-1] + W[k+1] when vertex k+1 is included.
![Thus, L[k+1] = max \{ L[k], \ L[k-1] + W[k+1] \}](https://tex.z-dn.net/?f=Thus%2C%20L%5Bk%2B1%5D%20%3D%20max%20%5C%7B%20L%5Bk%5D%2C%20%5C%20L%5Bk-1%5D%20%2B%20W%5Bk%2B1%5D%20%5C%7D)
As a result, the dynamic programming algorithm technique can be applied in the following way.
ALGO(V, W, n) // V is a linearly ordered series of n vertices with such a weight feature W
![\text{1. L[0] = 0, L[1] = W[1], L[2] = max{W[1], W[2]} //Base cases} \\ \\ \text{2. For i = 3 to n:- \\} \\ \\\text{3........ if ( L[i-1] > L[i-2] + W[ i ] )} \\ \\ \text{4............Then L[ i ] = L[i-1]} \\ \\ \text{5.........else} \\ \\ \text{6................L[i] = L[i-2] + W[i] }\\ \\ \text{7. Return L[n] //our answer.}](https://tex.z-dn.net/?f=%5Ctext%7B1.%20L%5B0%5D%20%3D%200%2C%20L%5B1%5D%20%3D%20W%5B1%5D%2C%20L%5B2%5D%20%3D%20max%7BW%5B1%5D%2C%20W%5B2%5D%7D%20%2F%2FBase%20cases%7D%20%5C%5C%20%5C%5C%20%5Ctext%7B2.%20For%20i%20%3D%203%20to%20n%3A-%20%5C%5C%7D%20%5C%5C%20%5C%5C%5Ctext%7B3........%20if%20%28%20L%5Bi-1%5D%20%3E%20L%5Bi-2%5D%20%2B%20W%5B%20i%20%5D%20%29%7D%20%5C%5C%20%5C%5C%20%5Ctext%7B4............Then%20L%5B%20i%20%5D%20%3D%20L%5Bi-1%5D%7D%20%5C%5C%20%5C%5C%20%5Ctext%7B5.........else%7D%20%5C%5C%20%5C%5C%20%5Ctext%7B6................L%5Bi%5D%20%3D%20L%5Bi-2%5D%20%2B%20W%5Bi%5D%20%7D%5C%5C%20%5C%5C%20%5Ctext%7B7.%20Return%20L%5Bn%5D%20%2F%2Four%20answer.%7D)
As a result, using dynamic programming, we can resolve the problem in O(n) only.
This is an example of a time-saving dynamic programming application.