MCQs
Kadane's algorithm uses a constant space. So, the space complexity is O(1).
The time complexity of the above dynamic programming implementation of the longest common subsequence is O(mn).
tmp_max is used to store the maximum length of an increasing subsequence for any 'j' such that: arr[j] < arr[i] and 0 < j < i.
So, tmp_max = LIS[j] completes the code.
Longest palindromic subsequence is an example of 2D dynamic programming.
The line arr[row][k] + arr[k + 1][col] + mat[row “ 1] * mat[k] * mat[col] should be inserted to complete the above code.
The space complexity of the above recursive implementation is O(1) because it uses a constant space.
The space complexity of the above Wagner“Fischer algorithm is O(mn).
The line t2[i] = get_min(t2[i-1]+spent[1][i], t1[i-1]+reach[0][i-1]+spent[1][i]) should be added to complete the above code.
A sum of 7 can be achieved in the following ways:
{1,1,1,1,1,1,1}, {1,1,1,1,3}, {1,3,3}, {1,1,1,4}, {3,4}.
Therefore, the sum can be achieved in 5 ways.
find_max(ans[itm “ 1][w “ wt[itm “ 1]] + val[itm “ 1], ans[itm “ 1][w]) completes the above code.