One-pass algorithm


In computing, a one-pass algorithm or single-pass algorithm is a streaming algorithm which reads its input exactly once. It does so by processing items in order, without unbounded buffering; it reads a block into an input buffer, processes it, and moves the result into an output buffer for each step in the process. A one-pass algorithm generally requires O time and less than O storage, where n is the size of the input. An example of a one-pass algorithm is the Sondik partially observable Markov decision process.

Example problems solvable by one-pass algorithms

Given any list as an input:
Given a list of numbers:
Given a list of symbols from an alphabet of k symbols, given in advance.
  • Count the number of times each symbol appears in the input.
  • Find the most or least frequent elements.
  • Sort the list according to some order on the symbols.
  • Find the maximum gap between two appearances of a given symbol.

    Example problems not solvable by one-pass algorithms

Given any list as an input:
Given a list of numbers:
  • Find the median.
  • Find the modes.
  • Sort the list.
  • Count the number of items greater than or less than the mean. However, this can be done in constant memory with two passes: Pass 1 finds the average and pass 2 does the counting.
The two-pass algorithms above are still streaming algorithms but not one-pass algorithms.