InterviewSolution
| 1. |
How Can Prefix Minima Be Found In O(1) Time? |
|
Answer» This can be computed by FIRST finding all nearest smaller VALUES first in O(1) and then CHECKING in O(1) time for each element (USING O(n) processor for that element), that largest index smaller than its own, whose element has no nearest smaller value on its left. The work complexity of O(n2) can be improved using accelerated cascading. This can be computed by first finding all nearest smaller values first in O(1) and then checking in O(1) time for each element (using O(n) processor for that element), that largest index smaller than its own, whose element has no nearest smaller value on its left. The work complexity of O(n2) can be improved using accelerated cascading. |
|