Diferente pentru blog/square-root-trick intre reviziile #52 si #53

Nu exista diferente intre titluri.

Diferente intre continut:

This algorithm takes $O(nm)$ time and only $O(n)$ space, since to compute a row you just need the previous row.
If you must return the actual sub sequence this doesn't work. You can keep an array of parent pointers, so that for each state $(i, j)$ you know the previous state in the solution. The longest sub sequence corresponds to a path from $(n-1, m-1)$ to $(0, 0)$ on the parent matrix.  This solution takes $O(nm)$ space.
Let's see how can we use less memory.
We solve the problem once and save every kth row from the best matrix and from the parent matrix.
Let's try to use less memory. We solve the problem once and save every kth row from the $best$ matrix and from the $parent$ matrix.
!<{margin-right: 20px; auto;display:block;}blog/square-root-trick?image02.png 90%!
We can start from the last saved row to compute the solution path from row $[n/k] * k$ to row $n - 1$. Then we go downwards to compute the part of the solution between the row $ik$ and the row $(i+1)k$ . Computing part of the path between row $ik$ and row $(i+1)k$ takes $O(km)$ space and $O(km)$ time. Computing the whole path takes $O(n/k (km)) = O(nm)$ time and $O(km)$ space. Saving the first pass rows takes $O([n/k]m)$ memory. Again, we minimize total memory usage by using $k = sqrt(n)$. This solution takes $O(sqrt(n)m)$ memory.

Nu exista diferente intre securitate.

Topicul de forum nu a fost schimbat.