3,749 views
3 3 votes
How to know that whether a sorting algorithm is online or offline ? For example , Insertion sort is online but Merge Sort is offline..Please explain ..

1 Answer

Best answer
13 13 votes

If you give input one by one to the algorithm and each input produces some partial solution with available input data. Then that type of algorithm is known as an online algorithm.

Here in insertion sort, we give input one by one and place each one at right order with comparison from already traces element. We need not the whole array simultaneous to operate algorithm. so it is online algorithm.

Let A[] = {23,1,4,2,7}

step:

1. A[] = {23,1,4,2,7}    ( only take 23 in consideration)

2. A[] = {1,23,4,2,7}  (only take 23,1 in consideration)

........................ and so on.

While in merge sort, it needs the whole array then algorithm start operation. so it is offline.

I hope you get little bit idea about this !!

Plz, comment if you have still doubt !!

• selected by
Position:
Show:

Related questions

9 9 votes
6 6 answers
4.0k
4.0k views
Arjun asked Feb 27, 2025
3,950 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...
1 1 vote
1 1 answer
136
136 views
GO Classes asked Aug 25
136 views
Let $P$ be the problem of sorting $n\geq1$ elements using only comparisons.Consider the class of all comparison-based algorithms that correctly solve $P$.What is the asym...
2 2 votes
2 2 answers
184
184 views
GO Classes asked Aug 11
184 views
Problem: Sort a file of huge records with tiny keys.Example application: Reorganize your MP-$3$ files.Which sorting method to use?a system sort, guaranteed to run in time...
1 1 vote
1 1 answer
121
121 views
GO Classes asked Aug 10
121 views
You need to sort hotels on a travel website according to their star rating.Which sorting algorithm would be the most appropriate?Insertion sort Merge sort Quicksort Bucke...