GateAI
Linear Structures, Trees and Heaps

GATE CSE 2020 · Q16

MCQ1 markEasy

Time

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

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) (n2)

Linear Structures, Trees and Heaps

To maintain a singly linked list in sorted order while inserting nn elements one by one:

  1. Inserting the 1st1^{\text{st}} element takes O(1)O(1) operations.

  2. In the worst case, inserting the kthk^{\text{th}} element requires traversing all k−1k-1 previously inserted elements to find the correct insertion position, taking Θ(k−1)\Theta(k-1) comparisons and pointer updates.

  3. The total worst-case time across all nn insertions is:

    ∑k=1nΘ(k−1)=Θ(n(n−1)2)=Θ(n2)\sum_{k=1}^{n} \Theta(k-1) = \Theta\left(\frac{n(n-1)}{2}\right) = \Theta(n^2)

Hence, the worst-case time complexity is Θ(n2)\Theta(n^2), which corresponds to option C.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

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 in GATE CSE

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 Heaps

More from GATE CSE 2020

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2020 · Q16 · MCQ

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.