Skip to content
GATEiit

GATE CSE 2020 Q16: Worst-case time to insert n^2 elements into an AVL tree of n

Question

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

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation

Answer: C (official GATE 2020 final answer key)

Concept used: Each AVL insertion costs O(log⁡m)O(\log m) for a tree of mm nodes.

First step: The tree never exceeds n+n2n + n^2 nodes, so each insertion is O(log⁡n2)=O(log⁡n)O(\log n^2) = O(\log n); multiply by n2n^2 insertions.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2020 CS question paper and final answer key, organised by IIT Delhi. Question paper · Answer key