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.
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
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
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 firstname.lastname@example.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.
- 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
- Optimized Longest Path is NP Complete
- Proof that 4 SAT is NP complete
- Proof that Collinearity Problem is NP Complete
- Subset Equality is NP Complete
- Proof that SAT is NP Complete
- Double SAT is NP Complete
- Hitting Set problem is NP Complete