All nearest smaller values

In computer science, the all nearest smaller values (ANSV) problem is: given an array , compute for each position the index , using a sentinel value (e.g. ) when no such exists. The corresponding nearest-smaller value is . Some presentations report , but many applications require the indices .

This problem can be solved efficiently both by parallel and non-parallel algorithms: Berkman, Schieber & Vishkin (1993), who first identified the procedure as a useful subroutine for other parallel programs, developed efficient algorithms to solve it in the Parallel Random Access Machine model; it may also be solved in linear time on a non-parallel computer using a stack-based algorithm. Later researchers have studied algorithms to solve it in other models of parallel computation.