GateAI
Asymptotic Analysis

GATE CSE 2020 · Q6

MCQ1 markMedium

Time

What is the worst case time complexity of inserting n2n^2 elements into an AVL-tree with nn elements initially?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) (n2 log n)

Asymptotic Analysis

An AVL tree is a self-balancing binary search tree. For an AVL tree containing kk elements, the height is Θ(log⁡k)\Theta(\log k), and the worst-case time to insert one element (including necessary rotations) is Θ(log⁡k)\Theta(\log k).

When inserting n2n^2 elements into an AVL tree initially containing nn elements:

  • For the ii-th insertion (1≤i≤n21 \le i \le n^2), the tree contains n+i−1n + i - 1 elements, taking Θ(log⁡(n+i))\Theta(\log(n + i)) time.

  • The total time complexity is:

    T(n)=∑i=1n2Θ(log⁡(n+i))T(n) = \sum_{i=1}^{n^2} \Theta(\log(n + i))

Bounding the sum:

T(n)≤∑i=1n2log⁡(n+n2)=n2log⁡(n2+n)=n2⋅Θ(log⁡n)=Θ(n2log⁡n)T(n) \le \sum_{i=1}^{n^2} \log(n + n^2) = n^2 \log(n^2 + n) = n^2 \cdot \Theta(\log n) = \Theta(n^2 \log n)
T(n)≥∑i=1n2log⁡n=n2log⁡n=Θ(n2log⁡n)T(n) \ge \sum_{i=1}^{n^2} \log n = n^2 \log n = \Theta(n^2 \log n)

Hence, the overall worst-case time complexity is Θ(n2log⁡n)\Theta(n^2 \log n), 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 Asymptotic Analysis previous year question is Q6 of the GATE CSE 2020 paper. Find more GATE CSE PYQs on Asymptotic Analysis in Algorithms, 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 Asymptotic Analysis 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.

Asymptotic Analysis in GATE CSE

Asymptotic Analysis has 31 GATE CSE PYQs across 19 papers from 2011 to 2026. 15 of them are 1-mark MCQs like this one, and GATE CSE 2020 has 2.

How GATE tests Asymptotic Analysis

More from GATE CSE 2020

Share this solution

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

GateAI solution cardGATE CSE 2020 · Q6 · MCQ

What is the worst case time complexity of inserting n2 elements into an AVL-tree with n elements initially?

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.