positional-based utility methods def recompute height(selfp) node height max( node left height) node right height)def isbalanced(selfp)return abs( node left heightp node right height)< def tall child(selfpfavorleft=false)parameter controls tiebreaker if node left height( if favorleft else node right height)return self left(pelsereturn self right(pdef tall grandchild(selfp)child self tall child(pif child is on leftfavor left grandchildelse favor right grandchild alignment (child =self left( )return self tall child(childalignmentdef rebalance(selfp)while is not nonetrivially if new node old height node height imbalance detectedif not self isbalanced( )perform trinode restructuringsetting to resulting rootand recompute new local heights after the restructuring self restructure(self tall grandchild( )self recompute height(self left( )self recompute height(self right( )adjust for recent changes self recompute height(phas height changedif node height =old heightp none no further changes needed elsep self parent(prepeat with parent override balancing hooks def rebalance insert(selfp)self rebalance(pdef rebalance delete(selfp)self rebalance(pcode fragment avltreemap class (continued from code fragment