Professional Documents
Culture Documents
22 Data Structures
http://ecomputernotes.com
http://ecomputernotes.com
Action: change the balance of the parent node and stop. No further effect on balance of any higher node.
http://ecomputernotes.com
2
1 3 5
6
7
http://ecomputernotes.com
2
1 3 5
6
7
2
3 5
6
7
remove(1)
http://ecomputernotes.com
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
Action: change the balance of the parent node. May have caused imbalance in higher nodes so continue up the tree.
http://ecomputernotes.com
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
http://ecomputernotes.com
Single rotate
Action: perform single rotation, adjust balance. No effect on balance of higher nodes so stop here.
http://ecomputernotes.com
10
http://ecomputernotes.com
11
double rotate
Action: Double rotation at B. May have effected the balance of higher nodes, so continue up the tree. 12
http://ecomputernotes.com
13
single rotate
Action: Single rotation at B. May have effected the balance of higher nodes, so continue up the tree. 14
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 b * c d * e
+
f
http://ecomputernotes.com
17
<term>
<factor> <id> C
Expression grammar <assign> <id> <expr> <term> <term> <factor> <factor> <id> := <expr> A | B | C <expr> + <term> | <term> * <factor> |
<id> A
( <expr> ) | <id>
18
http://ecomputernotes.com
19
<RelName> , <FromList>
title
StarsIn
<RelName>
MovieStar
http://ecomputernotes.com
Compiler Optimization
Common subexpression: (f+d*e)+((d*e+f)*g)
+
+
f d * e d +
*
g f e
21
http://ecomputernotes.com
Compiler Optimization
(Common subexpression: (f+d*e)+((d*e+f)*g)
+
+ f d * e
Graph!
http://ecomputernotes.com
22