Open In App

GATE | GATE CS 2020 | Question 26

Like Article
Like
Save
Share
Report

What is the worst case time complexity of inserting n elements into an empty linked list, if the linked list needs to be maintained in sorted order ?

(A)

Θ(n)

(B)

Θ(n log n)

(C)

Θ(n2)

(D)

Θ(1)


Answer: (C)

Explanation:

If we want to insert n elements into an empty linked list that needs to be maintained in sorted order, the worst-case time complexity would be O(n^2). This is because we would need to traverse the list for each element we want to insert, to find the correct position for the element in the sorted list.

 


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 11 Aug, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads