From WikipediaIn computer science, 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 start.  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.

Let us discuss the above facts with example of selection sort and insertion sort.

(1) In selection sort , For example [23, 4, 45,2 ,3 ,2,1], to sort this set in ascending order 23 is compared with all other elements in the list [4,45,2,3,2,1] and if 0th element is found to be greater then we swap the elements. This step is repeated for the next element.

(2) In insertion sort, For the same example [23, 4, 45,2 ,3 ,2,1], each element is compared with its previous elements.

From above It is clear that insertion sort does not require all the inputs before starting the algorithm’s steps while selection sort requires all the inputs before starting algorithm’s steps. Hence insertion sort is online while selection sort is offline algorithm.

Related Contents to follow