SlideShare a Scribd company logo
Class No.22

     Data Structures

http://ecomputernotes.com


                       1
Deletion in AVL Tree

  There are 5 cases to consider.
  Let us go through the cases graphically and
   determine what action to take.
  We will not develop the C++ code for
   deleteNode in AVL tree. This will be left as
   an exercise.



          http://ecomputernotes.com
                                  2
Deletion in AVL Tree

 Case 1a: the parent of the deleted node had a balance of 0
 and the node was deleted in the parent’s left subtree.




              Delete on
              this side




 Action: change the balance of the parent node and stop. No
 further effect on balance of any higher node.

             http://ecomputernotes.com
                                     3
Deletion in AVL Tree

 Here is why; the height of left tree does not change.


                               0
               4


       2               6       1


  1        3       5       7   2




               http://ecomputernotes.com
                                       4
Deletion in AVL Tree

 Here is why; the height of left tree does not change.


                                0
               4                                   4


       2               6        1          2               6


  1        3       5       7    2              3       5       7



                               remove(1)


               http://ecomputernotes.com
                                       5
Deletion in AVL Tree

 Case 1b: the parent of the deleted node had a balance of 0
 and the node was deleted in the parent’s right subtree.




                      Delete on
                      this side




 Action: (same as 1a) change the balance of the parent node
 and stop. No further effect on balance of any higher node.

             http://ecomputernotes.com
                                     6
Deletion in AVL Tree

 Case 2a: the parent of the deleted node had a balance of 1
 and the node was deleted in the parent’s left subtree.




              Delete on
              this side




 Action: change the balance of the parent node. May have
 caused imbalance in higher nodes so continue up the tree.

             http://ecomputernotes.com
                                     7
Deletion in AVL Tree

 Case 2b: the parent of the deleted node had a balance of -1
 and the node was deleted in the parent’s right subtree.




                        Delete on
                        this side




 Action: same as 2a: change the balance of the parent node.
 May have caused imbalance in higher nodes so continue up
 the tree.
            http://ecomputernotes.com        8
Deletion in AVL Tree

 Case 3a: the parent had balance of -1 and the node was
 deleted in the parent’s left subtree, right subtree was balanced.




             http://ecomputernotes.com
                                     9
Deletion in AVL Tree

 Case 3a: the parent had balance of -1 and the node was
 deleted in the parent’s left subtree, right subtree was balanced.



        Single rotate




 Action: perform single rotation, adjust balance. No effect on
 balance of higher nodes so stop here.
                                                10
Deletion in AVL Tree

 Case 4a: parent had balance of -1 and the node was deleted in
 the parent’s left subtree, right subtree was unbalanced.




            http://ecomputernotes.com
                                    11
Deletion in AVL Tree
 Case 4a: parent had balance of -1 and the node was deleted in
 the parent’s left subtree, right subtree was unbalanced.


        double
        rotate




 Action: Double rotation at B. May have effected the balance of
 higher nodes, so continue up the tree.
                                               12
Deletion in AVL Tree

 Case 5a: parent had balance of -1 and the node was deleted in
 the parent’s left subtree, right subtree was unbalanced.




            http://ecomputernotes.com
                                    13
Deletion in AVL Tree

 Case 5a: parent had balance of -1 and the node was deleted in
 the parent’s left subtree, right subtree was unbalanced.




        single
        rotate




 Action: Single rotation at B. May have effected the balance of
 higher nodes, so continue up the tree.
                                               14
Other Uses of Binary Trees

         Expression Trees




     http://ecomputernotes.com
                             15
Expression Trees

  Expression trees, and the more general
   parse trees and abstract syntax trees are
   significant components of compilers.
  Let us consider the expression tree.




          http://ecomputernotes.com
                                  16
Expression Tree

 (a+b*c)+((d*e+f)*g)
                      +


      +                                   *

  a           *                   +           g


          b       c           *       f

                          d       e

          http://ecomputernotes.com
                                  17
Parse Tree in Compiler

 A := A + B * C                            <assign>


                                    <id>     :=       <expr>


                                    A
                                           <expr>      +            <term>

                                           <term>
                                                       <term>         *      <factor>
                                           <factor>
                                                      <factor>                 <id>
                                            <id>
 Expression grammar
                                                        <id>                    C
                                             A
 <assign>    <id> := <expr>                               B
 <id>        A | B | C
 <expr>      <expr> + <term> |
 <term>
 <term>      <term> * <factor> |
 <factor>
 <factor>    ( <expr> ) | <id>                                18
Parse Tree for an SQL query
 Consider querying a movie database
   Find the titles for movies with stars born in 1960

 The database has tables
   StarsIn(title, year, starName)
   MovieStar(name, address, gender, birthdate)

 SELECT title
 FROM StarsIn, MovieStar
 WHERE starName = name AND birthdate LIKE ‘%1960’ ;


            http://ecomputernotes.com
                                    19
SQL Parse Tree
                            < Query >

 SELECT <SelList> FROM       <FromList>     WHERE       <Condition>

       <Attribute>   <RelName> , <FromList>                 AND

          title         StarsIn   <RelName>
                                    MovieStar


                             <Condition>                     <Condition>

             <Attribute>     =    <Attribute>    <Attribute> LIKE <Pattern>

             starName             name          birthdate         ‘%1960’


              http://ecomputernotes.com
                                      20
Compiler Optimization

 Common subexpression:
   (f+d*e)+((d*e+f)*g)
                      +


      +                                   *

  f           *                   +           g


          d       e           *       f

                          d       e
          http://ecomputernotes.com
                                  21
Compiler Optimization

 (Common subexpression:
   (f+d*e)+((d*e+f)*g)
                      +


      +                                *

  f           *                            g


          d       e
                          Graph!
          http://ecomputernotes.com
                                  22

More Related Content

Similar to Computernotes datastructures-22-111227202516-phpapp02

computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19ecomputernotes
 
Computer notes - The const Keyword
Computer notes - The const KeywordComputer notes - The const Keyword
Computer notes - The const Keyword
ecomputernotes
 
Binary Trees
Binary TreesBinary Trees
Binary Trees
Sadaf Ismail
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3
praveena p
 
Sienna 6 bst
Sienna 6 bstSienna 6 bst
Sienna 6 bstchidabdu
 
Computer notes data structures - 9
Computer notes   data structures - 9Computer notes   data structures - 9
Computer notes data structures - 9ecomputernotes
 
Optimizing the Catalyst Optimizer for Complex Plans
Optimizing the Catalyst Optimizer for Complex PlansOptimizing the Catalyst Optimizer for Complex Plans
Optimizing the Catalyst Optimizer for Complex Plans
Databricks
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
Om Prakash
 
Lecture 6 operators
Lecture 6   operatorsLecture 6   operators
Lecture 6 operators
eShikshak
 
Operator precedence
Operator precedenceOperator precedence
Operator precedence
Akshaya Arunan
 
A Critical Look at Fixtures
A Critical Look at FixturesA Critical Look at Fixtures
A Critical Look at FixturesActsAsCon
 
Computer notes - Expression Tree
Computer notes - Expression TreeComputer notes - Expression Tree
Computer notes - Expression Tree
ecomputernotes
 
computer notes - Data Structures - 23
computer notes - Data Structures - 23computer notes - Data Structures - 23
computer notes - Data Structures - 23ecomputernotes
 

Similar to Computernotes datastructures-22-111227202516-phpapp02 (15)

computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
Computer notes - The const Keyword
Computer notes - The const KeywordComputer notes - The const Keyword
Computer notes - The const Keyword
 
Binary Trees
Binary TreesBinary Trees
Binary Trees
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3
 
Sienna 6 bst
Sienna 6 bstSienna 6 bst
Sienna 6 bst
 
Computer notes data structures - 9
Computer notes   data structures - 9Computer notes   data structures - 9
Computer notes data structures - 9
 
Optimizing the Catalyst Optimizer for Complex Plans
Optimizing the Catalyst Optimizer for Complex PlansOptimizing the Catalyst Optimizer for Complex Plans
Optimizing the Catalyst Optimizer for Complex Plans
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
Lecture 6 operators
Lecture 6   operatorsLecture 6   operators
Lecture 6 operators
 
Operator precedence
Operator precedenceOperator precedence
Operator precedence
 
A Critical Look at Fixtures
A Critical Look at FixturesA Critical Look at Fixtures
A Critical Look at Fixtures
 
Computer notes - Expression Tree
Computer notes - Expression TreeComputer notes - Expression Tree
Computer notes - Expression Tree
 
computer notes - Data Structures - 23
computer notes - Data Structures - 23computer notes - Data Structures - 23
computer notes - Data Structures - 23
 

Recently uploaded

How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 

Recently uploaded (20)

How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

Computernotes datastructures-22-111227202516-phpapp02

  • 1. Class No.22 Data Structures http://ecomputernotes.com 1
  • 2. Deletion in AVL Tree  There are 5 cases to consider.  Let us go through the cases graphically and determine what action to take.  We will not develop the C++ code for deleteNode in AVL tree. This will be left as an exercise. http://ecomputernotes.com 2
  • 3. Deletion in AVL Tree Case 1a: the parent of the deleted node had a balance of 0 and the node was deleted in the parent’s left subtree. Delete on this side Action: change the balance of the parent node and stop. No further effect on balance of any higher node. http://ecomputernotes.com 3
  • 4. Deletion in AVL Tree Here is why; the height of left tree does not change. 0 4 2 6 1 1 3 5 7 2 http://ecomputernotes.com 4
  • 5. Deletion in AVL Tree Here is why; the height of left tree does not change. 0 4 4 2 6 1 2 6 1 3 5 7 2 3 5 7 remove(1) http://ecomputernotes.com 5
  • 6. Deletion in AVL Tree Case 1b: the parent of the deleted node had a balance of 0 and the node was deleted in the parent’s right subtree. Delete on this side Action: (same as 1a) change the balance of the parent node and stop. No further effect on balance of any higher node. http://ecomputernotes.com 6
  • 7. Deletion in AVL Tree Case 2a: the parent of the deleted node had a balance of 1 and the node was deleted in the parent’s left subtree. Delete on this side Action: change the balance of the parent node. May have caused imbalance in higher nodes so continue up the tree. http://ecomputernotes.com 7
  • 8. Deletion in AVL Tree Case 2b: the parent of the deleted node had a balance of -1 and the node was deleted in the parent’s right subtree. Delete on this side Action: same as 2a: change the balance of the parent node. May have caused imbalance in higher nodes so continue up the tree. http://ecomputernotes.com 8
  • 9. Deletion in AVL Tree Case 3a: the parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was balanced. http://ecomputernotes.com 9
  • 10. Deletion in AVL Tree Case 3a: the parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was balanced. Single rotate Action: perform single rotation, adjust balance. No effect on balance of higher nodes so stop here. 10
  • 11. Deletion in AVL Tree Case 4a: parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was unbalanced. http://ecomputernotes.com 11
  • 12. Deletion in AVL Tree Case 4a: parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was unbalanced. double rotate Action: Double rotation at B. May have effected the balance of higher nodes, so continue up the tree. 12
  • 13. Deletion in AVL Tree Case 5a: parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was unbalanced. http://ecomputernotes.com 13
  • 14. Deletion in AVL Tree Case 5a: parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was unbalanced. single rotate Action: Single rotation at B. May have effected the balance of higher nodes, so continue up the tree. 14
  • 15. Other Uses of Binary Trees Expression Trees http://ecomputernotes.com 15
  • 16. Expression Trees  Expression trees, and the more general parse trees and abstract syntax trees are significant components of compilers.  Let us consider the expression tree. http://ecomputernotes.com 16
  • 17. Expression Tree (a+b*c)+((d*e+f)*g) + + * a * + g b c * f d e http://ecomputernotes.com 17
  • 18. Parse Tree in Compiler A := A + B * C <assign> <id> := <expr> A <expr> + <term> <term> <term> * <factor> <factor> <factor> <id> <id> Expression grammar <id> C A <assign>  <id> := <expr> B <id>  A | B | C <expr>  <expr> + <term> | <term> <term>  <term> * <factor> | <factor> <factor>  ( <expr> ) | <id> 18
  • 19. Parse Tree for an SQL query Consider querying a movie database Find the titles for movies with stars born in 1960 The database has tables StarsIn(title, year, starName) MovieStar(name, address, gender, birthdate) SELECT title FROM StarsIn, MovieStar WHERE starName = name AND birthdate LIKE ‘%1960’ ; http://ecomputernotes.com 19
  • 20. SQL Parse Tree < Query > SELECT <SelList> FROM <FromList> WHERE <Condition> <Attribute> <RelName> , <FromList> AND title StarsIn <RelName> MovieStar <Condition> <Condition> <Attribute> = <Attribute> <Attribute> LIKE <Pattern> starName name birthdate ‘%1960’ http://ecomputernotes.com 20
  • 21. Compiler Optimization Common subexpression: (f+d*e)+((d*e+f)*g) + + * f * + g d e * f d e http://ecomputernotes.com 21
  • 22. Compiler Optimization (Common subexpression: (f+d*e)+((d*e+f)*g) + + * f * g d e Graph! http://ecomputernotes.com 22