I have a new answer like as follows
- Sort the K new elements with merge sort which takes O(K * Log K)
-
Now merge the two sorted arrays (Use Third Array, after finishing remove first and second arrays). The first array is already sorted which contains N elements and the second array contains K elements which in turn takes O(N + K) which is going to be O(N).
-
So, the total time complexity is going to be O(K * Log K) (First Step) + O(N) (Second Step)
-
Total time complexity is O( K * Log K + N)
3
solved Can any one help me out in sorting the array by inserting k new elements