SlideShare a Scribd company logo
1 of 22
HEIGHT BALANCED
TREE
M.NIVETHITHA,
DEPARTMENT OF INFORMATION TECHNOLOGY,
V.V.VANNIAPERUMAL COLLEGE FOR WOMEN,
VIRUDHUNAGAR.
BINARY TREE
2
a binary tree is a tree data structure in which each node has at most
two children, which are referred to as the left child and the right child.
Types of binary trees
1. Height balanced tree
2.Binary search tree
3.Heap tree
4.Threaded binary tree
5.Expression tree
3
1.Height balanced tree
“Height-balanced binary
tree : is defined as a
binary tree in which the
depth of the two sub trees
of every node never differ
by more than 1.”
5
definition
> A binary search tree is said to be a height
balanced binary search tree if all its nodes have
a balance factor of
1,0 or -1.
That is,
|bf|=|hL – hR| ≤ 1
For every node in tree.
6
example
7
The basic objectives of the height balanced tree
8
1.Searching
2.Insertion
3.deletion
These operations may not be with the minimum time but the time
involved is less than that of in an unbalanced binary search
tree.
9
How an unbalanced
binary tree converted
into a height balanced
tree
Suppose initially there
is a height balanced tree
10
The mechanism to balance an unbalance tree due to the insertion of a node
into it.
Steps :
1.Insert node into a binary search tree :
insert the node into its proper position following the properties of
binary tree
2.Compute the balance factors:
on the path starting from the root node to the node newly inserted,
compute the balance factors of each node.
3.Decide the pivot node :
on the path as traced in step 2, determine whether the absolute
value of any nodes balance factor is switched from 1 to 2.if so, the tree
11
becomes unbalanced. It is called Pivot node.
4.Balance the unbalance tree :
to manipulate pointers centred at the pivot node to bring the tree back
into height balance. This pointer manipulation is known as AVL Rotation
AVL ROTATIONS:
An elegant method was devised in 1962
By two Russian mathematicians ,
G.M.Adelson-Velskii
E.M.Landis
12
There are four cases of rotations
CASE 1 : LEFT TO LEFT INSERTION
 RIGHT SUB TREE OF LEFT CHILD OF PIVOT NODE BECOMES THE LEFT SUB TREE OF P.
 P BECOMES THE RIGHT CHILD OF A
 LEFT SUB TREE OF A REMAINS THE SAME
A
P
PR
AR
AL
A
P
AR
AL
PR
ALGORITHM
13
INPUT : Pointer Pptr to the pivot node
OUTPUT : AVL rotations corresponding to the unbalance due to insertion in the left sub tree
of the left child of Pptr
STEPS :
1.Aptr = Pptr - > LCHILD
2.Pptr-> LCHILD = Aptr->RCHILD
3.Aptr->RCHILD=Pptr
4.Pptr->HEIGHT=Compute Height(Pptr)
5.Aptr->HEIGHT=Compute Height(Aptr)
6.Pptr=Aptr
7.Stop
CASE 2 : RIGHT TO RIGHT INSERTION
14
 LEFT SUB TREE OF RIGHT CHILD OF PIVOT NODE BECOMES THE RIGHT SUB TREE OF P.
 P BECOMES THE LEFT CHILD OF A
 RIGHT SUB TREE OF A REMAINS THE SAME
A
P
AR
AL
PL
A
P
ALGORITHM
15
INPUT : Pointer Pptr to the pivot node
OUTPUT : AVL rotations corresponding to the unbalance due to insertion in the right sub
tree of the right child of Pptr
STEPS :
1.Aptr = Pptr - > RCHILD
2.Pptr-> RCHILD = Aptr->LCHILD
3.Aptr->LCHILD=Pptr
4.Pptr->HEIGHT=Compute Height(Pptr)
5.Aptr->HEIGHT=Compute Height(Aptr)
6.Pptr=Aptr
7.Stop
CASE 3 : LEFT TO RIGHT INSERTION
16
ROTATION 1 :
 LEFT SUB TREE OF THE RIGHT CHILD OF THE LEFT CHILD OF PIVOT NODE BECOMES
THE RIGHT SUB TREE OF THE LEFT CHILD.
 LEFT CHILD OF THE PIVOT NODE BECOMES THE LEFT CHILD OF B
ROTATION 2 :
 RIGHT SUBTREE OF THE RIGHT CHILD OF THE LEFT CHILD OF THE PIVOT NODE
BECOMES THE LEFT SUBTREE OF P
 P BECOMES THE RIGHT CHILD OF B
P
PR
AL
A
B
BL
BR
B
A
AL
BL
P
BR PR
ALGORITHM
17
INPUT : Pointer Pptr to the pivot node
OUTPUT : AVL rotations corresponding to the unbalance due to insertion in the right sub
tree of the left child of Pptr
STEPS :
1.Aptr = Pptr - > LCHILD
2.RightToRightRotation(Aptr)
3.LeftToLeftRotation(Pptr)
4.Stop
CASE 4 : RIGHT TO LEFT INSERTION
18
ROTATION 1 :
 RIGHT SUB TREE OF THE LEFT CHILD OF THE RIGHTCHILD OF PIVOT NODE BECOMES
THE LEFT SUB TREE OF A.
 RIGHT CHILD OF THE PIVOT NODE BECOMES THE RIGHT CHILD OF B.
ROTATION 2 :
 LEFT SUBTREE OF THE RIGHT CHILD OF THE RIGHT CHILD OF THE PIVOT NODE
BECOMES THE RIGHT SUBTREE OF P
 P BECOMES THE LEFT CHILD OF B
P
A
AR
PL
B
BL
BR
B
P
PL
BL
A
BR AR
ALGORITHM
19
INPUT : Pointer Pptr to the pivot node
OUTPUT : AVL rotations corresponding to the unbalance due to insertion in the left sub tree
of the right child of Pptr
STEPS :
1.Aptr = Pptr - > RCHILD
2. LeftToLeftRotation(Aptr)
3.RightToRightRotation(Pptr)
4.Stop
IMPLEMENTATION FOR
HEIGHT BALANCING
TREE
LCHILD DATA HEIGHT RCHILD
ALGORITHM
21
INPUT : Pointer PTR to the tree whose height has to be calculated
OUTPUT : Height of the tree
DATA STRUCTURE : Linked Structure of Height
STEPS :
1.If (PTR=NULL) then
2. Height = 0
3. Return(height)
4.Else
5. lptr=PTR->LCHILD
6. Rptr=PTR->RCHILD
7. Hl=Compute Height(lptr)
8. Hr=Compute Height(Rptr)
9. If(Hl <= Hr) then
10. height = 1 + Hr
11. Else
12. height = 1 + Hl
13. Endif
14. Return(height)
15. Endif
16. stop
22

More Related Content

What's hot

Video news package start to finish
Video news package start to finishVideo news package start to finish
Video news package start to finishDon Goble
 
Ejemplos de Diagrama y Elementos de las Paginas WEB
Ejemplos de Diagrama y Elementos de las Paginas WEBEjemplos de Diagrama y Elementos de las Paginas WEB
Ejemplos de Diagrama y Elementos de las Paginas WEBogms
 
Teoría de códigos
Teoría de códigosTeoría de códigos
Teoría de códigosYared Redman
 
unix- the process states, zombies, running jobs in background
unix-  the process states, zombies, running jobs in backgroundunix-  the process states, zombies, running jobs in background
unix- the process states, zombies, running jobs in backgroundDr. Girish GS
 
Redação jornalística como funciona pdf
Redação jornalística como funciona pdfRedação jornalística como funciona pdf
Redação jornalística como funciona pdfThais De Mendonça Jorge
 
Temario diseno-grafico-apuntes-temas-1-7
Temario diseno-grafico-apuntes-temas-1-7Temario diseno-grafico-apuntes-temas-1-7
Temario diseno-grafico-apuntes-temas-1-7JoanEsquivelArenas
 
MOBILE IP,DHCP,ADHOC ROUTING PROTOCOLS
MOBILE IP,DHCP,ADHOC ROUTING PROTOCOLSMOBILE IP,DHCP,ADHOC ROUTING PROTOCOLS
MOBILE IP,DHCP,ADHOC ROUTING PROTOCOLSManju La
 
Chapter 7 : Transport layer
Chapter 7 : Transport layerChapter 7 : Transport layer
Chapter 7 : Transport layerteknetir
 

What's hot (10)

Diagramação de Jornais
Diagramação de JornaisDiagramação de Jornais
Diagramação de Jornais
 
Video news package start to finish
Video news package start to finishVideo news package start to finish
Video news package start to finish
 
Ejemplos de Diagrama y Elementos de las Paginas WEB
Ejemplos de Diagrama y Elementos de las Paginas WEBEjemplos de Diagrama y Elementos de las Paginas WEB
Ejemplos de Diagrama y Elementos de las Paginas WEB
 
Teoría de códigos
Teoría de códigosTeoría de códigos
Teoría de códigos
 
Vox pop
Vox popVox pop
Vox pop
 
unix- the process states, zombies, running jobs in background
unix-  the process states, zombies, running jobs in backgroundunix-  the process states, zombies, running jobs in background
unix- the process states, zombies, running jobs in background
 
Redação jornalística como funciona pdf
Redação jornalística como funciona pdfRedação jornalística como funciona pdf
Redação jornalística como funciona pdf
 
Temario diseno-grafico-apuntes-temas-1-7
Temario diseno-grafico-apuntes-temas-1-7Temario diseno-grafico-apuntes-temas-1-7
Temario diseno-grafico-apuntes-temas-1-7
 
MOBILE IP,DHCP,ADHOC ROUTING PROTOCOLS
MOBILE IP,DHCP,ADHOC ROUTING PROTOCOLSMOBILE IP,DHCP,ADHOC ROUTING PROTOCOLS
MOBILE IP,DHCP,ADHOC ROUTING PROTOCOLS
 
Chapter 7 : Transport layer
Chapter 7 : Transport layerChapter 7 : Transport layer
Chapter 7 : Transport layer
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

Building Height Balanced Binary Trees

  • 1. HEIGHT BALANCED TREE M.NIVETHITHA, DEPARTMENT OF INFORMATION TECHNOLOGY, V.V.VANNIAPERUMAL COLLEGE FOR WOMEN, VIRUDHUNAGAR.
  • 2. BINARY TREE 2 a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.
  • 3. Types of binary trees 1. Height balanced tree 2.Binary search tree 3.Heap tree 4.Threaded binary tree 5.Expression tree 3
  • 5. “Height-balanced binary tree : is defined as a binary tree in which the depth of the two sub trees of every node never differ by more than 1.” 5
  • 6. definition > A binary search tree is said to be a height balanced binary search tree if all its nodes have a balance factor of 1,0 or -1. That is, |bf|=|hL – hR| ≤ 1 For every node in tree. 6
  • 8. The basic objectives of the height balanced tree 8 1.Searching 2.Insertion 3.deletion These operations may not be with the minimum time but the time involved is less than that of in an unbalanced binary search tree.
  • 9. 9 How an unbalanced binary tree converted into a height balanced tree Suppose initially there is a height balanced tree
  • 10. 10 The mechanism to balance an unbalance tree due to the insertion of a node into it. Steps : 1.Insert node into a binary search tree : insert the node into its proper position following the properties of binary tree 2.Compute the balance factors: on the path starting from the root node to the node newly inserted, compute the balance factors of each node. 3.Decide the pivot node : on the path as traced in step 2, determine whether the absolute value of any nodes balance factor is switched from 1 to 2.if so, the tree
  • 11. 11 becomes unbalanced. It is called Pivot node. 4.Balance the unbalance tree : to manipulate pointers centred at the pivot node to bring the tree back into height balance. This pointer manipulation is known as AVL Rotation AVL ROTATIONS: An elegant method was devised in 1962 By two Russian mathematicians , G.M.Adelson-Velskii E.M.Landis
  • 12. 12 There are four cases of rotations CASE 1 : LEFT TO LEFT INSERTION  RIGHT SUB TREE OF LEFT CHILD OF PIVOT NODE BECOMES THE LEFT SUB TREE OF P.  P BECOMES THE RIGHT CHILD OF A  LEFT SUB TREE OF A REMAINS THE SAME A P PR AR AL A P AR AL PR
  • 13. ALGORITHM 13 INPUT : Pointer Pptr to the pivot node OUTPUT : AVL rotations corresponding to the unbalance due to insertion in the left sub tree of the left child of Pptr STEPS : 1.Aptr = Pptr - > LCHILD 2.Pptr-> LCHILD = Aptr->RCHILD 3.Aptr->RCHILD=Pptr 4.Pptr->HEIGHT=Compute Height(Pptr) 5.Aptr->HEIGHT=Compute Height(Aptr) 6.Pptr=Aptr 7.Stop
  • 14. CASE 2 : RIGHT TO RIGHT INSERTION 14  LEFT SUB TREE OF RIGHT CHILD OF PIVOT NODE BECOMES THE RIGHT SUB TREE OF P.  P BECOMES THE LEFT CHILD OF A  RIGHT SUB TREE OF A REMAINS THE SAME A P AR AL PL A P
  • 15. ALGORITHM 15 INPUT : Pointer Pptr to the pivot node OUTPUT : AVL rotations corresponding to the unbalance due to insertion in the right sub tree of the right child of Pptr STEPS : 1.Aptr = Pptr - > RCHILD 2.Pptr-> RCHILD = Aptr->LCHILD 3.Aptr->LCHILD=Pptr 4.Pptr->HEIGHT=Compute Height(Pptr) 5.Aptr->HEIGHT=Compute Height(Aptr) 6.Pptr=Aptr 7.Stop
  • 16. CASE 3 : LEFT TO RIGHT INSERTION 16 ROTATION 1 :  LEFT SUB TREE OF THE RIGHT CHILD OF THE LEFT CHILD OF PIVOT NODE BECOMES THE RIGHT SUB TREE OF THE LEFT CHILD.  LEFT CHILD OF THE PIVOT NODE BECOMES THE LEFT CHILD OF B ROTATION 2 :  RIGHT SUBTREE OF THE RIGHT CHILD OF THE LEFT CHILD OF THE PIVOT NODE BECOMES THE LEFT SUBTREE OF P  P BECOMES THE RIGHT CHILD OF B P PR AL A B BL BR B A AL BL P BR PR
  • 17. ALGORITHM 17 INPUT : Pointer Pptr to the pivot node OUTPUT : AVL rotations corresponding to the unbalance due to insertion in the right sub tree of the left child of Pptr STEPS : 1.Aptr = Pptr - > LCHILD 2.RightToRightRotation(Aptr) 3.LeftToLeftRotation(Pptr) 4.Stop
  • 18. CASE 4 : RIGHT TO LEFT INSERTION 18 ROTATION 1 :  RIGHT SUB TREE OF THE LEFT CHILD OF THE RIGHTCHILD OF PIVOT NODE BECOMES THE LEFT SUB TREE OF A.  RIGHT CHILD OF THE PIVOT NODE BECOMES THE RIGHT CHILD OF B. ROTATION 2 :  LEFT SUBTREE OF THE RIGHT CHILD OF THE RIGHT CHILD OF THE PIVOT NODE BECOMES THE RIGHT SUBTREE OF P  P BECOMES THE LEFT CHILD OF B P A AR PL B BL BR B P PL BL A BR AR
  • 19. ALGORITHM 19 INPUT : Pointer Pptr to the pivot node OUTPUT : AVL rotations corresponding to the unbalance due to insertion in the left sub tree of the right child of Pptr STEPS : 1.Aptr = Pptr - > RCHILD 2. LeftToLeftRotation(Aptr) 3.RightToRightRotation(Pptr) 4.Stop
  • 21. ALGORITHM 21 INPUT : Pointer PTR to the tree whose height has to be calculated OUTPUT : Height of the tree DATA STRUCTURE : Linked Structure of Height STEPS : 1.If (PTR=NULL) then 2. Height = 0 3. Return(height) 4.Else 5. lptr=PTR->LCHILD 6. Rptr=PTR->RCHILD 7. Hl=Compute Height(lptr) 8. Hr=Compute Height(Rptr) 9. If(Hl <= Hr) then 10. height = 1 + Hr 11. Else 12. height = 1 + Hl 13. Endif 14. Return(height) 15. Endif 16. stop
  • 22. 22