Worst Case number of rotations for BST to AVL algorithm?

Posted by spacker_lechuck on Stack Overflow See other posts from Stack Overflow or by spacker_lechuck
Published on 2012-06-04T14:36:32Z Indexed on 2012/11/05 23:01 UTC
Read the original article Hit count: 183

I have a basic algorithm below and I know that the worst case input BST is one that has degenerated to a linked list from inserts to only one side.

How would I compute the worst case complexity in terms of number of rotations for this BST to AVL conversion algorithm?

IF tree is right heavy
{
  IF tree's right subtree is left heavy
  {
     Perform Double Left rotation 
  }
  ELSE
  {
     Perform Single Left rotation
  }
}
ELSE IF tree is left heavy
{
  IF tree's left subtree is right heavy
  {
     Perform Double Right rotation
  }
  ELSE
  {
     Perform Single Right rotation
  }
}

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about time-complexity