GATE 2020 CS – Question 26
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?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (C) $\Theta(n^2)$
Explanation
Each sorted insertion into a linked list needs a linear scan, with no binary search possible. Total is $1+2+\dots+n=\Theta(n^2)$.