An online algorithm is one that can process its input piece-by-piece in a serial fashion, i.e., in the order that the input is fed to the algorithm, without having the entire input available from the beginning.

In contrast, an **offline algorithm** is given the whole problem data from the beginning and is required to output an answer which solves the problem at hand.

As an example, consider the sorting algorithms **selection sort** and **insertion sort**:

The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. 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.

**EXAMPLE OF ONLINE ALGORITHM (INSERTION SORT):**

Because an online algorithm does not know the whole input, it might make decisions that later turn out not to be optimal,

Note that insertion sort produces the optimum result. Therefore, for many problems, online algorithms cannot match the performance of offline algorithms.

**Example of Online Algorithms are :**

1. Insertion sort

2. Perceptron

3. Reservoir sampling

4. Greedy algorithm

5. Adversary model

6. Metrical task systems

7. Odds algorithm

**Online Problems:** There are many problems that offer more than one online algorithm as solution:

1. Canadian Traveller Problem

2. Linear Search Problem

3. K-server problem

4. Job shop scheduling problem

5. List update problem

6. Bandit problem

7. Secretary problem

**Reference :**

https://en.wikipedia.org/wiki/Online_algorithm

This article is contributed by **Shubham Rana**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Analysis of Algorithm | Set 4 (Solving Recurrences)
- Analysis of Algorithm | Set 5 (Amortized Analysis Introduction)
- Algorithm Practice Question for Beginners | Set 1
- Jump Pointer Algorithm
- In-Place Algorithm
- Sorting algorithm visualization : Insertion Sort
- Sorting algorithm visualization : Heap Sort
- Extended Disjoint Set Union on Trees
- Determine winner of the Game by arranging balls in a row
- Difference between Big Oh, Big Omega and Big Theta
- Check if Pascal's Triangle is possible with a complete layer by using numbers upto N
- Count subarrays having sum of elements at even and odd positions equal
- Sorting algorithm visualization : Heap Sort
- Find position of non-attacking Rooks in lexicographic order that can be placed on N*N chessboard