Question 13
With the same notation as in the previous questions, consider the following alternate approach. We first organize the disks in non-decreasing order of heights, that is, is a disk that has the smallest height, while is a disk that has the largest height.
We process the DP array in increasing order of indices (i.e, to ). We look at all disks where such that can be placed on top of .
If can be placed on top of , then is updated to be the maximum of and , where is the height of the disk .
What can you say about this approach?
This approach is correct.
This approach is incorrect, because we might miss some disks that can be placed on top of di, as the given array may not be sorted by height.
This approach is incorrect because the values we are looking up may not be computed correctly when we need them.