Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Explanation:-

As the question says linked list order needs to be maintained in sorted order,

But nowhere it is mentioned that sorted order needs to be maintained after


every insertion. Overall it should be sorted.

We can simply insert all the elements at the beginning of the linked list and then
sort it using merge sort which will take O(nlogn) time .

The Linked list insertion operations will take O(1) time. It means a constant
amount of time for insertion. Total number of elements inserted into an empty
linked list is O(n). So, it will take O(n) time in the worst case.

After inserting elements into an empty linked list we have to perform sorting
operation. To get minimum time complexity to perform sorting order is merge
sort. It will give O(nlogn) time complexity only.

Below is the detailed solution.

You might also like