Gate2020 cs Q33

0. What is the worst case time complexity of inserting n2 elements into an AVL Tree with n elements initially?

  • Option : A
  • Explanation :
    Insertion of an element into AVL requires O(log n) time.
    To insert an element
    1. Find the position, where to insert
    2. After insertion, to satisfy AVL properly, we may need to perform rotation.
    So, (1) take ‘log n time’ and (2) take ‘log n’ time.
    Total time for inserting one element into AVL tree is
    log n + log n = 2 log n ⇒ O (log n).
    Now, To insert n2 elements ⇒ n2 log n
    ⇒ O(n2 log n)
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *