2 2 votes 47. An array ' $A$ ' contain ' $I$ ' number of Inversions then what is the Time Complexity of insertion sort algorithm to sort ' $n$ ' element of array ' $A$ '? $\mathrm{O}(\mathrm{n}+\mathrm{I})$ $\mathrm{O}\left(\mathrm{n}^{2}+\mathrm{I}\right)$ $\mathrm{O}\left(\mathrm{n}^{3}+\mathrm{I}\right)$ $\mathrm{O}\left(\mathrm{n}^{4}+\mathrm{I}\right)$ Algorithms algorithms time-complexity test-series + – Payal Rastogi 1.3k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply Umang Raman commented Nov 14, 2015 i edited by Umang Raman Nov 14, 2015 reply Follow flag Let A[1....n] be an array of n distinct numbers . if i<j and A[i] > A[j] then the pair (i ,j) is called an inversion pair of A. 3 3 replyShare Arjun commented Nov 14, 2015 i reshown by Pooja Palod Dec 1, 2015 reply Follow flag https://gateoverflow.in/4550/time-complexity https://gateoverflow.in/949/gate2003_61-62 3 3 replyShare Please log in or register to add a comment.
Best answer 2 2 votes If the given array is already sorted and maximum n inversion is possible then insertion sort gives best case for that array because array is already sorted.i.e O(n)e.g. = 10 20 30 40 50 60 1 : here 6 inversion and array is almost sorted so it will take 6 comparison and 6 swaps if array is of n element and 1 element is not sorted then : O(n) for searching the position n swap O(2n) for n element n*2n = O(n2)So we can say if in array there are I inversion is there then Time Complexity = O(n + I) O(n) for best case for I= n O(n2) for worst case if I is more than noptiion A Umang Raman answered Nov 15, 2015 • selected Nov 15, 2015 by Payal Rastogi Umang Raman comment Share Follow 0 reply Please log in or register to add a comment.
2 2 votes Insersion sort will take O( n2 ) using merge sort complexity will be O(nlogn) Prashant. answered Nov 15, 2015 Prashant. comment Share Follow 0 reply Please log in or register to add a comment.