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?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2020 · Q16
Time
Select one answerSingle correct
Solution
Official answer: C) (n2)
Linear Structures, Trees and HeapsTo maintain a singly linked list in sorted order while inserting elements one by one:
Inserting the element takes operations.
In the worst case, inserting the element requires traversing all previously inserted elements to find the correct insertion position, taking comparisons and pointer updates.
The total worst-case time across all insertions is:
Hence, the worst-case time complexity is , which corresponds to option C.
Try the question first, then check your work.
Examiner trap
Consider the number of comparisons needed to insert the -th element when it must be placed at the very end of a list containing elements.
This Linear Structures, Trees and Heaps previous year question is Q16 of the GATE CSE 2020 paper. Find more GATE CSE PYQs on Linear Structures, Trees and Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Linear Structures, Trees and Heaps PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Linear Structures, Trees and Heaps has 14 GATE CSE PYQs across 12 papers from 2012 to 2026. 7 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2020.
How GATE tests Linear Structures, Trees and HeapsIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.