Jump to content

One-pass algorithm

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dmh (talk | contribs) at 15:38, 14 April 2021 (Remove text on cluster representatives. It's specific to databases, and the mechanics are covered under streaming algorithm). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computing, a one-pass algorithm or single-pass algorithm is a streaming algorithm which reads its input exactly once, in order, without unbounded buffering. A one-pass algorithm generally requires O(n) (see 'big O' notation) time and less than O(n) storage (typically O(1)), where n is the size of the input.[1]

Example problems solvable by one-pass algorithms

Given any list as an input:

  • Count the number of elements.

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 (possible since the number of symbols is limited).
  • 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:

  • Find the nth element from the end (or report that the list has fewer than n elements).
  • Find the middle element of the list.

Given a list of numbers:

  • Find the median.
  • Find the modes (This is not the same as finding the most frequent symbol from a limited alphabet).
  • Sort the list.

References

  1. ^ Schweikardt, Nicole (2009), LIU, LING; ÖZSU, M. TAMER (eds.), "One-Pass Algorithm", Encyclopedia of Database Systems, Boston, MA: Springer US, pp. 1948–1949, doi:10.1007/978-0-387-39940-9_253, ISBN 978-0-387-39940-9, retrieved 2021-04-13