Lably
Skip to content

Online algorithm

Algorithm that begins on possibly incomplete inputs

  • 3 min read
  • 2 chapters

Related on Lably

Through Computer science, Algorithm and Insertion sort

In operations research, the area in which online algorithms are developed is called online optimization.

As an example, consider the sorting algorithms selection sort and insertion sort: selection sort repeatedly selects the minimum element from the unsorted remainder and places it at the front, which requires access to the entire input; it is thus an offline algorithm. On the other hand, insertion sort considers one input element per iteration and produces a partial solution without considering future elements. Thus insertion sort is an online algorithm.

Note that the final result of an insertion sort is optimum, i.e., a correctly sorted list. For many problems, online algorithms cannot match the performance of offline algorithms. If the ratio between the performance of an online algorithm and an optimal offline algorithm is bounded, the online algorithm is called competitive.

Not every offline algorithm has an efficient online counterpart.

Definition

Because it does not know the whole input, an online algorithm is forced to make decisions that may later turn out not to be optimal, and the study of online algorithms has focused on the quality of decision-making that is possible in this setting. Competitive analysis formalizes this idea by comparing the relative performance of an online and offline algorithm for the same problem instance. Specifically, the competitive ratio of an algorithm, is defined as the worst-case ratio of its cost divided by the optimal cost, over all possible inputs. The competitive ratio of an online problem is the best competitive ratio achieved by an online algorithm. Intuitively, the competitive ratio of an algorithm gives a measure on the quality of solutions produced by this algorithm, while the competitive ratio of a problem shows the importance of knowing the future for this problem.

Other interpretations

For other points of view on online inputs to algorithms, see

  • streaming algorithm: focusing on the amount of memory needed to accurately represent past inputs;
  • dynamic algorithm: focusing on the time complexity of maintaining solutions to problems with online inputs.

Examples

Some online algorithms:

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication