Professional Documents
Culture Documents
Explanation - Ques-16 - Compressed
Explanation - Ques-16 - Compressed
As the question says linked list order needs to be maintained in sorted order,
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.