DATA STRUCTURES
AVL TRESS
B.ABINAYA BHARATHI M.Sc[Cs&IT]
NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE
THENI
1
AVL TREES
 AVL tree is a self-balancing Binary Search Tree
 AVL tree balances itself by making rotations when the tree
becomes unbalanced.
 when inserting a element in binary search tree ,The tree
becomes a gigantic line.
 if the size of the tree is n elements,
 performing each insertion takes n operations.
 Performing all n insertions takes roughly n2
operations. 2
BALANCE FACTOR
 In a binary tree the balance factor of a node N is
used
 Balance Factor(N) = Height( RightSubtree(N) ) –
Height( LeftSubtree(N) )
 Balance Factor(N) ∈ {–1,0,+1}
3
ROTATION
 To balance itself, an AVL tree may perform the following four
kinds of rotations −
 Left rotation
 Right rotation
 Left-Right rotation
 Right-Left rotation
 The first two rotations are single rotations
 The next two rotations are double rotations. 4
ROTATIONS IN AVL TREES
5
LEFT ROTATION
 In LL Rotation every node moves one position to left from the
current position.
6
RIGHT RIGHT ROTATION
o In RR Rotation every node moves one position to right from
the current position.
7
LEFT RIGHT ROTATION
o The LR Rotation is combination of single left rotation
followed by single right rotation.
o In LR Rotation, first every node moves one position to left
then one position to right from the current position.
8
RIGHT LEFT ROTATION
oThe RL Rotation is combination of single right rotation
followed by single left rotation.
oIn RL Rotation, first every node moves one position to right
then one position to left from the current position.
9
THANK YOU
10

data structures

  • 1.
    DATA STRUCTURES AVL TRESS B.ABINAYABHARATHI M.Sc[Cs&IT] NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE THENI 1
  • 2.
    AVL TREES  AVLtree is a self-balancing Binary Search Tree  AVL tree balances itself by making rotations when the tree becomes unbalanced.  when inserting a element in binary search tree ,The tree becomes a gigantic line.  if the size of the tree is n elements,  performing each insertion takes n operations.  Performing all n insertions takes roughly n2 operations. 2
  • 3.
    BALANCE FACTOR  Ina binary tree the balance factor of a node N is used  Balance Factor(N) = Height( RightSubtree(N) ) – Height( LeftSubtree(N) )  Balance Factor(N) ∈ {–1,0,+1} 3
  • 4.
    ROTATION  To balanceitself, an AVL tree may perform the following four kinds of rotations −  Left rotation  Right rotation  Left-Right rotation  Right-Left rotation  The first two rotations are single rotations  The next two rotations are double rotations. 4
  • 5.
  • 6.
    LEFT ROTATION  InLL Rotation every node moves one position to left from the current position. 6
  • 7.
    RIGHT RIGHT ROTATION oIn RR Rotation every node moves one position to right from the current position. 7
  • 8.
    LEFT RIGHT ROTATION oThe LR Rotation is combination of single left rotation followed by single right rotation. o In LR Rotation, first every node moves one position to left then one position to right from the current position. 8
  • 9.
    RIGHT LEFT ROTATION oTheRL Rotation is combination of single right rotation followed by single left rotation. oIn RL Rotation, first every node moves one position to right then one position to left from the current position. 9
  • 10.