time complexity - Worst Case number of rotations for BST to AVL algorithm? -
i have basic algorithm below , know worst case input bst 1 has degenerated linked list inserts 1 side.
how compute worst case complexity in terms of number of rotations bst avl conversion algorithm?
if tree right heavy { if tree's right subtree left heavy { perform double left rotation } else { perform single left rotation } } else if tree left heavy { if tree's left subtree right heavy { perform double right rotation } else { perform single right rotation } }
if single , double rotations take constant time o(1) worst-case input on size n going perform single (or double depending on if input linked list left-sided or right-sided) on nodes. be:
o(1) + o(1) + ... + o(1) # n times worst case that makes algorithm o(n) worst case.
Comments
Post a Comment